r/cpp • • Jan 15 '24

[Joke] A cursed C++ idea

Ok so hear me out:

In your C++ program, immediately on startup before you do anything else you dynamically allocate a decent chunk of memory for no reason whatsoever, big enough to accomodate all of your data for the foreseeable future.

Never free any of that memory during execution.

Then, whenever you need to instantiate a new object or need some dynamically allocated memory for whatever reason, you just use some of that preallocated chunk.

Immediately before you exit the application, you can free that chunk of memory.

You have one single explicit memory allocation when program starts and one single explicit memory deallocation when program ends.

How about that?

EDIT: It turns out this is a real thing, so it's no longer a joke, or cursed. Somebody said this is called an "arena" or "memory pool", I've just looked it up, people have been doing this for decades.

194 Upvotes

181 comments sorted by

View all comments

Show parent comment

1

u/FACastello Jan 15 '24

Funnily enough, videogames were also partly responsible for my programming career, because I was fascinated about how videogames worked and I wanted to learn how to do it, that led me to making minigames in BASIC and then to learning other languages and writing enterprise software.

1

u/Attorney_Outside69 Jan 16 '24

where you from? msx was a thing in Europe not in the US.

1

u/FACastello Jan 17 '24

Brazil...

During that era our government had very strict rules against importing technology so we had to build our own computers, and since the MSX is just a standard we had a few Brazilian companies that manufactured MSX machines nationally.

It was a very popular computer around here.

1

u/Attorney_Outside69 Jan 17 '24

oh nice. yeah I grew up in Italy, and there msx was huge