packed

Is there a fast product operation for PackedArrays?

跟風遠走 提交于 2019-12-03 00:18:22
In Mathematica a vector (or rectangular array) containing all machine size integers or floats may be stored in a packed array. These objects take less memory, and some operations are much faster on them. RandomReal produces a packed array when possible. A packed array can be unpacked with the Developer function FromPackedArray Consider these timings lst = RandomReal[1, 5000000]; Total[lst] // Timing Plus @@ lst // Timing lst = Developer`FromPackedArray[lst]; Total[lst] // Timing Plus @@ lst // Timing Out[1]= {0.016, 2.50056*10^6} Out[2]= {0.859, 2.50056*10^6} Out[3]= {0.625, 2.50056*10^6} Out

Packed bit fields in c structures - GCC

和自甴很熟 提交于 2019-12-02 22:47:50
I am working with structs in c on linux. I started using bit fields and the "packed" attribute and I came across a wierd behavior: struct t1 { int a:12; int b:32; int c:4; }__attribute__((packed)); struct t2 { int a:12; int b; int c:4; }__attribute__((packed)); void main() { printf("%d\n",sizeof(t1)); //output - 6 printf("%d\n",sizeof(t2)); //output - 7 } How come both structures - that are exactly the same - take diffrent number of bytes? Your structures are not "exactly the same". Your first one has three consecutive bit-fields, the second has one bit-field, an (non bit-field) int, and then

Are packed structs portable?

只愿长相守 提交于 2019-12-02 19:01:51
I have some code on a Cortex-M4 microcontroller and'd like to communicate with a PC using a binary protocol. Currently, I'm using packed structs using the GCC-specific packed attribute. Here is a rough outline: struct Sensor1Telemetry { int16_t temperature; uint32_t timestamp; uint16_t voltageMv; // etc... } __attribute__((__packed__)); struct TelemetryPacket { Sensor1Telemetry tele1; Sensor2Telemetry tele2; // etc... } __attribute__((__packed__)); My question is: Assuming that I use the exact same definition for the TelemetryPacket struct on the MCU and the client app, will the above code be

Nothing but “packed” records — should I fix it?

纵饮孤独 提交于 2019-11-30 20:46:09
While reviewing some code in our legacy Delphi 7 program, I noticed that everywhere there is a record it is marked with packed . This of course means that the record is stored byte-for-byte and not aligned to be faster for the CPU to access. The packing seems to have been done blindly as an attempt to outsmart the compiler or something -- basically valuing a few bytes of memory instead of faster access An example record: TFooTypeRec = packed record RID : Integer; Description : String; CalcInTotalIncome : Boolean; RequireAddress : Boolean; end; Should I fix this and make every record normal or

Are there any difference between array and packed array in Delphi?

≯℡__Kan透↙ 提交于 2019-11-28 08:25:12
In C/C++ you always have SizeOf(array[N] of T) = N * SizeOf(T); In Pascal/Delphi you can use 'packed array' to be sure that the above assert is true, but does 'packed' specifier have any practical value for arrays in Delphi? I can't create an example of 'unpacked' array, the arrays seems always 'packed': type A = array[0..2] of Byte; B = array[0..99] of A; C = packed record C1, C2, C3: Byte; end; D = array[0..99] of C; procedure TForm10.Button1Click(Sender: TObject); begin Assert(SizeOf(A) = 3); Assert(SizeOf(B) = 300); Assert(SizeOf(D) = 300); end; (The C/C++ structures and Delphi records are

What is a “packed” structure in C?

女生的网名这么多〃 提交于 2019-11-27 12:22:22
I am going though some C code written for the Microchip C30 compiler and I often see structs defined as follows: typedef struct __attribute__((__packed__)) { IP_ADDR MyIPAddr; // IP address IP_ADDR MyMask; // Subnet mask IP_ADDR MyGateway; // Default Gateway // etc... } APP_CONFIG; What does packed mean? When structures are defined, the compiler is allowed to add paddings (spaces without actual data) so that members fall in address boundaries that are easier to access for the CPU. For example, on a 32-bit CPU, 32-bit members should start at addresses that are multiple of 4 bytes in order to be

Are there any difference between array and packed array in Delphi?

喜欢而已 提交于 2019-11-27 02:18:15
问题 In C/C++ you always have SizeOf(array[N] of T) = N * SizeOf(T); In Pascal/Delphi you can use 'packed array' to be sure that the above assert is true, but does 'packed' specifier have any practical value for arrays in Delphi? I can't create an example of 'unpacked' array, the arrays seems always 'packed': type A = array[0..2] of Byte; B = array[0..99] of A; C = packed record C1, C2, C3: Byte; end; D = array[0..99] of C; procedure TForm10.Button1Click(Sender: TObject); begin Assert(SizeOf(A) =

What is a “packed” structure in C?

纵然是瞬间 提交于 2019-11-26 15:58:58
问题 I am going though some C code written for the Microchip C30 compiler and I often see structs defined as follows: typedef struct __attribute__((__packed__)) { IP_ADDR MyIPAddr; // IP address IP_ADDR MyMask; // Subnet mask IP_ADDR MyGateway; // Default Gateway // etc... } APP_CONFIG; What does packed mean? 回答1: When structures are defined, the compiler is allowed to add paddings (spaces without actual data) so that members fall in address boundaries that are easier to access for the CPU. For