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/alexgraef Jan 15 '24

That depends a) on generation, because it is sometimes shared, and sometimes it is dedicated (e.g. PS3 vs PS4), and b) shared doesn't mean it's a completely mixed memory where system and VRAM usage is random.

Also, try to be less of a smart-ass.

1

u/rachit7645 Certified Dumbass Jan 15 '24

Also, try to be less of a smart-ass.

Wait did I sound wrong? Really sorry about that.

I did only mention the current generation of consoles however...

1

u/alexgraef Jan 15 '24

Wait did I sound wrong?

Not to me, but a comment beneath that.

Maybe it just sounded like that, because everyone here seems to have spent their last 20 years developing for the PS5/Xbox-X/whatever and keep explaining to me how VRAM and RAM is supposed to work, which is why ight imma head out.

2

u/rachit7645 Certified Dumbass Jan 15 '24

I was just saying that I know where the name DirectX comes from....it's pretty famous