CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2001
    Posts
    210

    Divide the buffer into chunks

    Hi !!!
    I wana divide a buffer into small size buffers..
    As an example ...
    I have a buffer of length 128k and i want to divide the buffer into 10k size.

    One way is .. Read the data into an char array ... and then byte by byte get the data and copy to buffer...

    Is there some good way or any method availabe .. in c library.

    UmaR

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Is there really a need to divide the buffer into smaller chunks? Without allocation new memory and copying data, you can still logically treat the buffer as separate chunks.

    Code:
    char largeBuffer[128*1024];
    
    char* chunk0 = &largeBuffer[0];
    char* chunk1 = &largeBuffer[10*1024];
    char* chunk2 = &largeBuffer[2*10*1024];
    char* chunk3 = &largeBuffer[3*10*1024];

  3. #3
    Join Date
    Dec 2003
    Posts
    99
    why do you need an intermediate char array?
    your buffer itself should(can) be a char array.
    memcpy() is a better choice unless the data is streaming in.


    Regards

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured