Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Aug 2003

    Dynamic Allocation Problem with HBufC8

    Hope you are doing well. I am facing a serious allocation problem. I try to create a buffer of variable size using following call.

    iDynamicBuffer = HBufC8::NewL(iBufferLen);

    TDes8 *des = &iDynamicBuffer->Des();
    i = des->MaxSize(); // always rounded to 4
    i = des->MaxLength() // always rounded to 4

    However whatever may be the value of iBufferLen I always get the return value rounded up to next 4 byte boundary. I accepted this and tried to work around with it. But then inconsistently the system started returning me more bytes then I am requesting. For example if I ask for 120 bytes it returns me 124 bytes sometime but not always. The problem is that I am using socket calls and I only want to read 120 bytes, but since the buffer size sometime becomes 124 and if network has 124 bytes available then it returns 124 bytes or if it doesnt have then it just waits for 124 bytes to arrive. My system wants that the socket read should return whenever it has read a particular amount of data e.g. 120. Any clue why it is happening. RecvOneOrMore is also a problem because of this behaviour because it may also return 124 sometimes. There is no way of specifying size in the socket reads except that the size comes from the MaxLength of the buffer.

    Any help is appreciated.



  2. #2
    Registered User
    Join Date
    Apr 2003
    Anyone have any ideas? I'm running into this too. I hacked around it by making my sender pad all transfers to even multiples of 4, but there's gotta be a better way!

    -- Rob

  3. #3
    Nokia Developer Moderator
    Join Date
    Mar 2003
    yep, it's very annoying and haven't really seen solution for it.

    Anyway as a workaround I used to use two step communication method, first reading the header of the incoming data and then the data itself.

    The header is small and always same size, so I can use TBuf8 type of buffer for it. then when I know the size of the incoming data so can make Hbuf8 for it and just call RecvOneOrMore() as meny times as I need to get all the data that I need.


  4. #4
    Regular Contributor
    Join Date
    Oct 2003
    Hi there,

    If you are reading from a socket try to read with a constant TBuf8 and then insert into a CBufFlat. I'm doing that way and it works ok. Just try to set granularity equal to TBuf8 length.

    I hope it helps.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts