My program uses a buffer to store data as entered by the user, so that the size of the buffer depends on them. The first thing that came to mind is that I would reallocate memory each time more storage is needed, but that doesn't seem reasonable as the data is small and the program would constantly be reallocating. How does one generally deal with a constantly expanding buffer?
Somersett
0
Newbie Poster
Recommended Answers
Jump to PostOne thing is you need to reallocate memory dynamically... As you say calling realloc always for small data size ain't a good idea... In such a case you can allocate chunks of memory at time... like 32 bytes, 64 bytes, 128 bytes and so on... whenever your data exceeds the …
Jump to PostWhat are you planning to do with the input, when you've finished reading it?
Jump to PostIt occurred to me that I might just increase the size of the chunk being reallocated, but burning questions arose: How do I determine what's a large enough size? I have trouble choosing things arbitrarily like this, and I begin to wonder whether reallocating single integers wouldn't affect my program …
All 9 Replies
ahamed101
40
Junior Poster
Salem
5,138
Posting Sage
Somersett
0
Newbie Poster
ahamed101
40
Junior Poster
Somersett
0
Newbie Poster
Sci@phy
97
Posting Whiz in Training
Somersett
0
Newbie Poster
Sci@phy
97
Posting Whiz in Training
Somersett
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.