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.
- 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.Tono Nam– Tono Nam2020-07-25 14:40:10 +00:00Commented 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?Delta_G– Delta_G2020-07-25 16:34:25 +00:00Commented 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.Tono Nam– Tono Nam2020-07-27 03:28:06 +00:00Commented 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.Delta_G– Delta_G2020-07-27 03:50:50 +00:00Commented 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.Delta_G– Delta_G2020-07-27 03:53:33 +00:00Commented Jul 27, 2020 at 3:53
| Show 1 more comment
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. arduino-uno), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cpp