[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.5.1 SDLNet_AllocPacket

`UDPpacket *SDLNet_AllocPacket(int size)`

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

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.

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

    // 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:
3.5.4 SDLNet_AllocPacketV, 3.5.2 SDLNet_ResizePacket, 3.5.3 SDLNet_FreePacket, 3.4.6 SDLNet_UDP_Send, 3.4.8 SDLNet_UDP_SendV, 4.4 UDPpacket

This document was generated on November, 3 2009 using texi2html