You are not logged in.

#1 2011-12-07 17:52:10

GalacticArachnid
Member
Registered: 2009-01-02
Posts: 155
Website

Intermidiate (?) question

So im trying to design a system where code efficiency is paramount, as such I absolutely must avoid any unnecessary memory copy stages. With that in mind..


The program will receive video buffers (v4l) and then send them out (kinda rtp style). When forming my (lets say)rtp packet, i do not want to copy a block of this video frame and then try and send it, instead Im planning on using the power of pointers read a chunk of data from that buffer.

I have a nice typedef struct my_packet_of_awesomeness_t {};   to describe the packet structure, and I was thinking if its possible to have the payload as a pointer to the memory location of this data buffer.

Could I then send this packet out by using a pointer to the struct's location?

so say we have:

typedef struct my_packet_of_awesomeness_t
{
    int some_flags;    // or whatever, 
    int more_stuff;     //  just some example stuff.
    
    unsigned char   *payload;   //this is meant to point to the buffer
};

can I know have something like:

int send_my_data( int blah, struct my_packet_of_awesomeness_t *packet )
{

void *index = &packet[ 0 ];

// (   ...   )

while( offset < length )
    {
        if(( length - offset )< UDP_DATA_SIZE )
            sent = sendto( port_fd, 
                           &index[ offset ],
                           ( length - offset ),
                           0, 
                           root->ai_addr,
                           root->ai_addrlen 
                         );

          //(  ...  )
          offset += sent;

and in the main() loop we would have:

int main( int argc, char *argv[] )
{
    unsigned char *buffer;
    struct my_packet_of_awesomeness_t le_packet;

    //various code that set everything up, blah blah blah
   
    le_packet->payload = &buffer;

    x = send_my_data( blah, &le_packet );

Any thoughts?

Offline

#2 2011-12-09 18:47:46

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: Intermidiate (?) question

GalacticArachnid wrote:

Could I then send this packet out by using a pointer to the struct's location?

No.

Offline

Board footer

Powered by FluxBB