xHarbour Reference Documentation > Function Reference |
Calculates the amount of memory required to store a C structure.
HB_SizeofCStructure( <aTypes>, [<nAlign>] ) --> nBytes
Constants for C-data types
Constant | C-data type |
---|---|
CTYPE_CHAR | char |
CTYPE_UNSIGNED_CHAR | unsigned char |
CTYPE_CHAR_PTR | char * |
CTYPE_UNSIGNED_CHAR_PTR | unsigned char* |
CTYPE_SHORT | short |
CTYPE_UNSIGNED_SHORT | unsigned short |
CTYPE_SHORT_PTR | short * |
CTYPE_UNSIGNED_SHORT_PTR | unsigned short * |
CTYPE_INT | int |
CTYPE_UNSIGNED_INT | unsigned int |
CTYPE_INT_PTR | int * |
CTYPE_UNSIGNED_INT_PTR | unsigned int * |
CTYPE_LONG | long |
CTYPE_UNSIGNED_LONG | unsigned long |
CTYPE_LONG_PTR | long * |
CTYPE_UNSIGNED_LONG_PTR | unsigned long * |
CTYPE_FLOAT | float |
CTYPE_FLOAT_PTR | float * |
CTYPE_DOUBLE | double |
CTYPE_DOUBLE_PTR | double * |
CTYPE_VOID_PTR | void * |
CTYPE_STRUCTURE | struct |
CTYPE_STRUCTURE_PTR | struct * |
The function returns the memory requirement for a structure as a numeric value in bytes.
Function HB_SizeOfCStructure() is used to calculate the size of a C structure in bytes. This depends on the number of bytes each C data type of structure members occupies in memory, and the byte alignment. The returned value is then used to create a character string like Replicate(Chr(0), nBytes). This character string can then be passed by reference to an API function via DllCall(). When DllCall() returns, the changed C structure string is decoded with function HB_StructureToArray().
An easier way of obtaining the size of a C structure is to declare a C structure class with typedef struct and call method :sizeOf() of a C structure object.
See also: | C Structure class, HB_ArrayToStructure(), HB_StructureToArray(), pragma pack() |
Category: | C Structure support , xHarbour extensions |
Header: | cstruct.ch |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
http://www.xHarbour.com