   char memory allocation question
  Hi all,Probably a stupid question - oh well here goes...This is memory before the allocation:00990EA0  DD DD DD DD DD DD DD DD  ........00990EA8  DD DD DD DD DD DD DD DD  ........00990EB0  DD DD DD DD DD DD DD DD  ........00990EB8  DD DD DD DD DD DD DD DD  ........00990EC0  DD DD DD DD DD DD DD 00  ........00990EC8  00 03 00 00 31 01 00 00  ....1...This is the allocation statement:unsigned char *buffer = (unsigned char*)malloc(32);This is the memory after the allocation:00990EA0  CD CD CD CD CD CD CD CD  ÍÍÍÍÍÍÍÍ00990EA8  CD CD CD CD CD CD CD CD  ÍÍÍÍÍÍÍÍ00990EB0  CD CD CD CD CD CD CD CD  ÍÍÍÍÍÍÍÍ00990EB8  CD CD CD CD CD CD CD CD  ÍÍÍÍÍÍÍÍ00990EC0  FD FD FD FD DD DD DD 00  ýýýý....00990EC8  51 00 00 00 31 01 00 00  Q...1...As far as I understand only the first 32 bytes should havebeen set to CD (undefined, right?) - so what''s going on inthe memory?!?thnx,atlnewbie  
  If you want the first 32 bytes to be CD I can''t see the problem here. The first 32 bytes are CD (count the CDs, each CD is one byte). Maybe you counted C as one byte and D as another?-Benny-  ;  yes you're right, sorry for being unclear.i was interested in why the other bytes after the first 32bytes (bytes 33-37, 41-42) were changed as well.thnx,atlnewbieEdited by - atlnewbie on November 13, 2001 8:56:36 AM  ;  if you are running this as a debug version in VC++ then it will probably be becuase VC++ allocates more memory than you request so that it can check if you go past the memory you allocate.  ;  I hope you''re not expecting to get 32 char pointers from that statement.  ;aha!yes i am running in debug.thanks!!atlnewbie  ;  Why are the values changed from DD to CD when the memory is allocated ? I wouldnt expect them to be altered at all.Just wondering ;  Thanks for the help!Can i use the debug mode for stepping throughthe code and viewing the memory - but withoutthe compiler doing extra fancy stuff like that?(i'm using msvc++6.0 enterprise)atlnewbieEdited by - atlnewbie on November 13, 2001 10:27:20 AM  ;quote:Original post by NewDeal   Why are the values changed from DD to CD when the memory is allocated ? I wouldnt expect them to be altered at all.Just wondering   VC++ has a bunch of difference constants that it uses to fill memory depending on the type of memory (unallocated, uninitialized heap memory, uninitialized stack memory, etc.). Filling it helps you figure out programming bugs. For example, if a for loop in your code isnt working right, and you set a breakpoint in the debugger and look at your local variables, and you see your loop-termination-variable has the hex value CD, you can be *pretty sure* the reason your loop isnt working is because you forgot to initialize the variable. It just makes things easier to figure out. Anytime you see a variable with one of these pre-initialized values, it should throw up a warning to you that you *MIGHT* have forgot to initialize something.Edited by - LordKronos on November 13, 2001 1:37:03 PM  ;  The MSVC++ malloc library places a small amount of data at the end of each allocated block. When you free the block, the library checks to make sure that the data hasn''t been changed: if it has then this is a likely indication that you''ve accidently overrun the end of the block.If this happens, you''ll receive a damage after Normal block   message upon freeing the memory.    All your bases belong to us   (I know. It''s irony.)  