Tao.Sdl SDK Documentation

SdlNet.SDLNet_AllocPacket Method 

Allocate a new UDP packet with a data buffer

[Visual Basic]
Public Shared Function SDLNet_AllocPacket( _
   ByVal size As Integer _
) As IntPtr
[C#]
public static IntPtr SDLNet_AllocPacket(
   int size
);

Parameters

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

Return Value

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

Remarks

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.

Binds to C-function call in SDL_net.h:

            extern DECLSPEC UDPpacket * SDLCALL SDLNet_AllocPacket(int size)
            

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 Class | Tao.Sdl Namespace | SdlNet.UDPpacket | SdlNet.IPaddress | SDLNet_AllocPacketV | SDLNet_ResizePacket | SDLNet_FreePacket | SDLNet_UDP_Send | SDLNet_UDP_SendV