I want to reserve a block of memory (1GB) to load data into it for analysis. Each record is about 10K bytes and there is at least 100k records. Originally I was going to use malloc in c++ code but I was advised against it.
Now, will using char * block = new char[1000000000] require additional memory to store the pointers to each of the 1,000,000,000 elements in the array? Will using char * block = malloc(1000000000 * sizeof(char)) require less additional memory to create than new[]?
My goal is to use the least amount of memory possible and don't want to be swamping records in and out of memory.
Thanks :)
newactually does ? Would you be surprised to read that it combines a call to malloc to allocate the memory and a call to a constructor to build the object (if last part is relevant) ? - Serge Ballestamallocandnewalmost certainly use the same underlying allocator. Why were you advised against it? - Jonathan Pottermalloc()just gives you a chunk of memory.new()will actually run a bunch of code to give you an object, which will internally domalloc()anyways to give you the same space you'd get with calling malloc yourself. - Marc Bchar? - Steve Summitstd::vectorandstd::vector::reserveorstd::vector::resize? - Daniel