struct packet array sizes?

This is a discussion on struct packet array sizes? within the C Programming forums, part of the General Programming Boards category; Hi I have a strut variable that I am using as a packet template for communication within my C application: ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    58

    Question struct packet array sizes?

    Hi

    I have a strut variable that I am using as a packet template for communication within my C application:

    Code:
    typedef struct
    {
      uint8_t        			header[HEADER_OFFSET]; 
      uint8_t			   	payload[MAX_PACKET_LENGTH];
      uint8_t        			footer[AFFIX_LENGTH - FOOTER_OFFSET]; 
    } PACK GenericPacket_t;
    The payload of the packets can change from anywhere from 11 bytes to 84 bytes, however defining the payload length in the way shown above leaves allot of unused space in the payload.

    Eg: If I want to send an 11 byte message the payload will still contain another 73 unused bytes)

    The packets sizes are especially critical with my system, done anyone know how I could define the structure above without forever setting the payload size to the maximum but still be able to send a full 84 byte message if I need to?

    thanks for any advice you can give

    David

    PS: I cannot use dynamic memory allocation - at all

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You will need to have your code that sends the actual packet know how long the payload itself is, and then make sure that it doesn't use the size of the packet data structure, but he size of the header, payload and footer to determine how much data is actually being sent.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-05-2009, 06:35 AM
  2. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 03:16 AM
  3. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  4. Writing an array of struct to file
    By stellastarr in forum C Programming
    Replies: 10
    Last Post: 03-25-2006, 06:59 PM
  5. memory allocation for flexible array member of struct
    By jcarouth in forum C Programming
    Replies: 3
    Last Post: 09-11-2005, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21