当前位置:主页>仓库管理软件> 列表

一个低级的问题~~~~ 找进销存需求

仓库管理软件版1楼: 结构体加packed和不加packed有什么区别啊

2楼: 抄的

举个帮助中的例子:
packed array[1..1000] of integer
正常情况下 array[1..1000] of integer 中的每个数据占用同样大小的内存
而packed array[1..1000] of integer 中是根据实际数据值需要内存的大小确定每个
数据占用的内存
PACKED ARRAY 节约了内存。 却因为数据内存中保存的不定长牺牲了查找定位速度。 如erp软件供应商

3楼: 那用法上有什么讲究呢

4楼: 帮助中说是添加了packed以后,可以压缩数据存储;代价是访问速度会受到影响!
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 compressed data storage. For example,



type TNumbers = packed array[1..100] of Real;

Using packed slows data access and, in the case of a character array, affects type compatibility (for more information, see Memory management).

5楼: 主要是在做那些事情的时候
要特别注意呢?

6楼: 以现在的计算机的运算速度和内存,如果结构体不是很大的话,没必要用 packed 关键字!

仓库管理软件版7楼: 正在看贴学习。长知识呀。。。。好[:)]

8楼: Using packed slows data access and, in the case of a character array, affects type compatibility

使用packed 影响数据访问速度 尤其是字符数组 影响数据完整性

9楼: 速度是一个重要的因素

10楼: 那就不要用packed 在机器性能很差数据较大的情况下

11楼: 举个例子:
Txxx = record
i: integer;
w: word;
end;
Tyyy =packed record
i: integer;
w: word;
end;
在默认的情况下,w 和 i 对齐,也占 4 个字节,所以 SizeOf(Txxx)=8
由于 Tyyy 是 Packed 所以 SizeOf(Tyyy)=6 (i - 4 字节,w - 2 字节)
在读写内存、文件时应特别注意。
有时为了与其它程序兼容、或调用某些 API、或调用某些第三方函数,或重点考虑 size 时不得不用 Packed。

12楼: 其实我最注重的不是速度,而是写操作


当你写内存的时候,如果不加packed 这样就会导致错误 如进销存需求

13楼: 对于变体记录用packed也许能使变体部分对齐,
如:
type ex=packed record
x:integer;
case t:byte of
1: a,b:byte;
2: c,d:integer;
end;
一般delphi按4的倍数为边界储存数据吧,packed是不是改变这种边界,让内寸占的确少点.
一知半解的,高手指点