I was wondering which would be better to use for the allocation of memory. The memory that is being allocated will almost certainly have to be reallocated several times.
I am making a string class (how original :) and I am going to give it dynamic memory allocation (whether or not that is the correct term...)
I actually made one a while back, and it was simply a disgrace, (I had used new/delete method, but in a very crude manner) I have recently recreated the entire thing (from the ground up), and have found malloc/realloc/free to be much more easy to use, and the string class (bcstring) works good now.
If you take experience and ease out of the picture, which would be the better choice to use.
What are some pros of each method?
Some cons?
My code can be found at: http://pscode.com/vb/scripts/BrowseCategoryOrSearchResults.asp?txtCriteria=bcstring&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUE&lngWId=3&optSort=Alphabetical
Recommended Answers
Jump to Post>I am making a string class
If you want it to be as flexible as possible, you'd do something like the standard string class and use an allocator. The default for allocators are new and delete. However, you're free to use whatever you want since this is …
Jump to Postyou might find the following article (about efficient memory management of typed buffers) instructive. i did, when i first read it. reading alexandrescu almost always has that effect.
http://www.ddj.com/cpp/184403806
(the article is failry old; …
Jump to Post> The main reason I am not using new and delete, is because 1. I tried that, and failed miserably
If that is all you did, then there are hidden bugs somewhere else in your code. Simply changingchar *p = new[10];
forchar *p = malloc(10);
in itself should …
All 9 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.