Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Again in your real life example you are allocating objects of different sizes (names). That will lead to heap fragmentation. If you where to allocate names of the same size and very few of them it is perfectly fine to use heap allocation. Commented Jul 25, 2020 at 14:40
  • But like I said in the example, if you’re allocating a fixed number of things of a fixed size then why do you want to use dynamic allocation to do that? What would be the advantage at that point? Commented Jul 25, 2020 at 16:34
  • That if I have multiple queues I do not have to create one buffer for each. There might be cases when allocation is helpful. My point is that if you understand how it works it is ok to use it. Probably most of the time it makes no sense to use it but not never. Commented Jul 27, 2020 at 3:28
  • Yeah not never, but not for what you're thinking either. You run into the same issue. If you have multiple queues and you want them to be able to share a buffer space then it would certainly be easier to have one buffer allocated and a single class that is controlling adding and removing. I'm thinking probably anything that can add to the queue needs to inherit some base class that allows you to have code in one place doing it. That is exactly the use case I'm on about where you think you know what you're doing and one day some corner case you never suspected bites you. Commented Jul 27, 2020 at 3:50
  • I guess it's one of those things that you just can't truly learn any way but the hard way. But at the end of the day, if you want shared buffer space you must put a limit on its size and if you're going to do that then you might as well allocate it all and let your code control putting things in and out. Commented Jul 27, 2020 at 3:53