PDA

View Full Version : ... packed?



MSK
سه شنبه 21 مهر 1383, 18:34 عصر
سلام!

اگه یکی از دوستان محبت کنه و برای من توضیح بده پیشوند packed در تعریف متغیرها به چه کاری میاد ممنون میشم! (:D)

من فکر میکردم یه جور روند برای فشرده سازی آرایه های هجیم و رکورد های بزرگه(مثل آپشن کمپرس درایوهای انتی اف اس). :oops:

ولی یه بار محض امتحان یه آرایه 100000 بایتی تعریف کردم ولی یه بایتم کم نشد. :cry:

:?:

مهدی کرامتی
سه شنبه 21 مهر 1383, 20:05 عصر
مفهوم رو اشتباه گرفتی برادر.

نقل قول از راهنمای دلفی:

<span dir=ltr>When a record type is declared in the {$A+} state (the default), and when the declaration does not include a packed modifier, the type is an unpacked record type, and the fields of the record are aligned for efficient access by the CPU. The alignment is controlled by the type of each field and by whether fields are declared together. Every data type has an inherent alignment, which is automatically computed by the compiler. The alignment can be 1, 2, 4, or 8, and represents the byte boundary that a value of the type must be stored on to provide the most efficient access. The table below lists the alignments for all data types.</span>

Type alignment masks
Type Alignment
Ordinal types size of the type &#40;1, 2, 4, or 8&#41;
Real types 2 for Real48, 4 for Single, 8 for Double and Extended
Short string types 1
Array types same as the element type of the array.
Record types the largest alignment of the fields in the record
Set types size of the type if 1, 2, or 4, otherwise 1
All other types determined by the $A directive.
<span dir=ltr>To ensure proper alignment of the fields in an unpacked record type, the compiler inserts an unused byte before fields with an alignment of 2, and up to three unused bytes before fields with an alignment of 4, if required. Finally, the compiler rounds the total size of the record upward to the byte boundary specified by the largest alignment of any of the fields.
If two fields share a common type specification, they are packed even if the declaration does not include the packed modifier and the record type is not declared in the {$A-} state. Thus, for example, given the following declaration</span>

type
TMyRecord = record
A, B&#58; Extended;
C&#58; Extended;
end;
<span dir=ltr>A and B are packed (aligned on byte boundaries) because they share the same type specification. The compiler pads the structure with unused bytes to ensure that C appears on a quadword boundary.

When a record type is declared in the {$A-} state, or when the declaration includes the packed modifier, the fields of the record are not aligned, but are instead assigned consecutive offsets. The total size of such a packed record is simply the size of all the fields. Because data alignment can change, it's a good idea to pack any record structure that you intend to write to disk or pass in memory to another module compiled using a different version of the compiler.</span>

omidsm
چهارشنبه 22 مهر 1383, 06:42 صبح
حالا نمی شد یه کمی فارسی توضیح بدین :sunglass: ::نوشتن::

_alish_
چهارشنبه 22 مهر 1383, 07:06 صبح
لطف میکنید بیشتر تو ضیح دهید البته در مورد alignment Data Type .ممنون

MSK
پنج شنبه 23 مهر 1383, 15:16 عصر
:roll:
اینطور که من برداشت کردم packed یعنی فواصلی که کامپایلر برای دسترسی آسان به متغیر ایجاد می کند را حذف کند!(البته در رکورد). :متفکر:

پس در آرایه ها کاربردی ندارد؟

در ضمن میشه به فارسی یه کم بیشتر توضیح دهید. چون همش رو هم متوجه نشدم :sorry: (البته اگر همین را درست متوجه شده باشم)

MSK
یک شنبه 26 مهر 1383, 21:04 عصر
نقل قول از دلفی:

Instances of a structured type hold more than one value. Structured types include sets, arrays, records, and files as well as class, class-reference, and interface types. Except for sets, which hold ordinal values only, structured types can contain other structured types; a type can have unlimited levels of structuring.

By default, the values in a structured type are aligned on word or double-word boundaries for faster access. When you declare a structured type, you can include the reserved word packed to implement &#91;b&#93;compressed&#91;/b&#93; data storage. For example,

type TNumbers = packed array&#91;1..100&#93; of Real;

Using packed slows data access and, in the case of a character array, affects type compatibility &#40;for more information, see &#91;u&#93;Memory management&#91;/u&#93;&#41;.
البته در نهایت از راهنمایی شما ممنون(ایراد از گیرنده بوده). :oops:

الیش عزیز در خصوص سوال شما به بخشی که آندر لاین شده در هلپ دلفی مراجعه کن.
(در ضمن به pmها هم جواب بده) :evil:

MSK
یک شنبه 26 مهر 1383, 21:05 عصر
شرمنده تو تگ کد مثل اینکه آندر لاین نمیشه! :sunglass:

omidsm
دوشنبه 27 مهر 1383, 06:10 صبح
یعنی هیچ یک از اساتید در مورد این موضوع حوصله ندارند یه چند سطر فارسی تایپ کنن :قهر: :گیج: :خیلی متعجب: :? :(

MSK
دوشنبه 04 آبان 1383, 13:43 عصر
عزیز دل برادر در روشی که cpu به متغیرها دسترسی می کنه براش دسترسی به آدرس های زوج(یا توانی از دو)راحتتره.

نتیجه اینکه دلفی برای سریعتر شدن برنامه متغیرهارو در چنین آدرسهایی قرار میده.

حالا ممکنه بعضی وقتا در استفاده از آرایه ها و رکورد ها نخواهیم این طوری بشه یعنی بخواهیم همه اعضای آرایه یا رکورد پشت سر هم باشه. اون موقع از packed استفاده می کنیم.

:flower: