Let's say im writing an application in c++

Let's say im writing an application in c++.
How would I tell the computer that I want to use exactly this amount of memory, right there, and no more?

Other urls found in this thread:

en.m.wikipedia.org/wiki/Memory_pool
twitter.com/SFWRedditGifs

why would you want something like this?

because I want the computer to do what I tell it to do.

then don't use OS

systemd settings

The amount can be easily controlled.
The location? It's up to the OS.

You could in a very ugly fashion create this static big array with all the memory you want to use and just make everything with pointers to this block of memory.

Why is that ugly?

All the manual memory management and manual pointer assigning you will be doing.

isnt manual memory management the point of using something like c++?

No

In this case, you would have to create your own memory allocator/delocator function that counts the bytes used manually.

Its called a buffer, but buffers assign certain amounts of memory to certain parts of code like variables.. you can't just tell your program how much memory to use as a whole, it's not how it works

so manual memory management is not important for efficiency?

No, C and C++ just have that low-level feature. Most programming languages do it automatically, by creating a virtual heap. There has to be memory management of some kind. But manual management isn't necessary.

actually the efficiency comes from not using a garbage collector, BUT c++ tries to make memory management as painless as possible, unlike C where you have to do everything with malloc() and free(). it's about as automatic as you can get without a GC

But I could in principle do:

char appMemory[1024];

if all I needed for my entire application was 1 KB?

Just writing Include I/O stream and setting namespace to std will take up more than 1Kb, im not sure you know how this works. You can't use magic to just make everything like you want it by force

OP this is what you want.
en.m.wikipedia.org/wiki/Memory_pool
You will have to size your pool(s) on instantiation then use pool allocation instead on the default c++ allocators.

Is it really magic to tell the computer that you want something of this size, and use that?

It is. You can't magically turn a kilobyte into less than a kilobyte without removing actual bytes

malloc
free

>setting namespace to std
JUST

You need a working meltdown exploit for that

Do you really need that level of control? If so, use C, not C++.

assembler