Array memory map

This is a discussion on Array memory map within the C Programming forums, part of the General Programming Boards category; Just some clarification if you wouldn't mind. If I allocated an array like so: char MyBuffer[127][256]; Would I get a ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    245

    Array memory map

    Just some clarification if you wouldn't mind.

    If I allocated an array like so:

    char MyBuffer[127][256];

    Would I get a guaranteed contiguous buffer of 32512 bytes (127*256), or would some implementations of C only guarantee 256 bytes in one contiguous chunk?

    Or, in other words, is the above equivalent to:

    char MyBuffer[32512];

    Apart from the way you access it?

    I want to clear the entire array to zeros without using a for loop to do each element. If the entire array is guaranteed to be contiguous, then I can just call ZeroMemory once instead of 127 times.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    5
    It will never be equal to a 32512 array as char ** is not a char * and it never will be. I don't see a problem with looping, no matter how you choose to zero it (high level) it will turn out to be a loop in the compiled code.

    Arrays of all kinds are contiguous (by definition).

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Thanks for the clarification.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help -- allocating memory in a multidimensional array
    By jonathan.plumb in forum C Programming
    Replies: 10
    Last Post: 05-21-2009, 12:04 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  3. How to Map a Memory Space
    By jacob12 in forum C Programming
    Replies: 6
    Last Post: 10-04-2008, 11:19 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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