C++ Dynamically Allocating string arrays

+1 Spencer Zammit · March 27, 2015
Hey guys i have this project I'm working on and I need to dynamically allocate these string arrays so that the size is always the size of whats actually the file. I understand the concept but I don't understand how to implement the code into what I have now. Please help. Thank you.

This is the code: https://gist.github.com/de5cc0b64318b12ac3af

Post a Reply

Replies

Oldest  Newest  Rating
0 Spencer Zammit · March 27, 2015
what im trying to do is make it so that the arrays knows how many items there are when it reads it in so it doesnt make it bigger than it needs to be.
0 Dol Lod · March 27, 2015
Personally, I would not recommend allocating that much memory b/c it would mean one continuous block. 10 GB should not be done that way. 

Solution 1: Create an array with the size ranging from 1 kilobyte to 100 Mb. Copy the contents of what you want to write repeatedly into that array. Write it out and then reset the contents again until the final iteration. On the final iteration, memset with the null byte ,copy the contents, and then write out to disk. Personally, I think this idea is much more feasible b/c it requires a smaller amount of data overall.

Solution 2: This is more wasteful, but is better than allocating that much memory in one block. I would divide it up into an array of pointers, maybe 1 kilobyte each and write those out to disk instead using a for loop.
  • 1

C++

107,185 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator