SDLNet_AllocPacket

Name

SDLNet_AllocPacket -- allocate a new UDP packet with a data buffer.

Synopsis

UDPpacket *SDLNet_AllocPacket(int size)

size Size, in bytes, of the data buffer to be allocated in the new UDPpacket. Zero is invalid.

Description

Create (via malloc) a new UDPpacket with a data buffer of size bytes.

The new packet should be freed using SDLNet_FreePacket when you are done using it.

Return Value

Returns: a pointer to a new empty UDPpacket. NULL is returned on errors, such as out-of-memory.

Example

// create a new UDPpacket to hold 1024 bytes of data
UDPpacket *packet;

packet=SDLNet_AllocPacket(1024);
if(!packet) {
    printf("SDLNet_AllocPacket: %s\n", SDLNet_GetError());
    // perhaps do something else since you can't make this packet
}
else {
    // do stuff with this new packet
    // SDLNet_FreePacket this packet when finished with it
}

See Also

SDLNet_AllocPacketV, SDLNet_ResizePacket, SDLNet_FreePacket, SDLNet_UDP_Send, SDLNet_UDP_SendV, UDPpacket

SDLNet_AllocPacket (last edited 2008-04-17 08:18:21 by localhost)