W
Wen
Hi all,
I have a structure with variable length information. To properly
define it, I use the following data structure:
typedef struct
{
HeaderInfo* headerInfo;
ContentInfo* contentInfo;
} PacketInfo;
typedef struct
{
UInt8 numNeighbors;
NeighborInfo* neighborInfo;
} HeaderInfo;
typedef struct
{
UInt8 ip;
UInt8 port;
} NeighborInfo;
typedef struct
{
Char* content;
} ContentInfo;
Basically the situation is: both header and content are variable
length, which can only be determined during runtime.
Following the definition of those structures (assuming those are
properly defined), how can I allocate memory to define an instance of
Packet? And how do I free the memory? Thanks a lot in advance!
I have a structure with variable length information. To properly
define it, I use the following data structure:
typedef struct
{
HeaderInfo* headerInfo;
ContentInfo* contentInfo;
} PacketInfo;
typedef struct
{
UInt8 numNeighbors;
NeighborInfo* neighborInfo;
} HeaderInfo;
typedef struct
{
UInt8 ip;
UInt8 port;
} NeighborInfo;
typedef struct
{
Char* content;
} ContentInfo;
Basically the situation is: both header and content are variable
length, which can only be determined during runtime.
Following the definition of those structures (assuming those are
properly defined), how can I allocate memory to define an instance of
Packet? And how do I free the memory? Thanks a lot in advance!