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 …
Jump to Post>1. I tried that, and failed miserably (mem. allocation failed,
>and only one class could be made for reasons unknown)
Then you're not using it correctly. Getting it to work will be a good learning experience.>all I have to do is realloc(whatever).
The design of realloc is questionable, …
Jump to Post>I did, but it returns an error.
Search whatever reference you want for the <memory> header.>So, as I understand it I should go ahead and go for new/delete
Why not?>and I'm guessing I should implement some sort of error checking?
…
That's generally a good idea, yes.
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.