Is it possible to store data to CPU memory, if so how much memory can I store and how?
Say I wanted to store an array, about 6MB in size?
Using ASM yes.. Iunno what you mean by CPU memory but I assume you mean registers. Just look up some x86 tutorials and download fasm get familiar with some commands then in your compiler, you can do something similar to:
__asm
{
push ebp
mov ebp,esp
mov ecx, 0x6;
mov eax, SomeData;
push....
;do crap here..
pop....
mov esp, ebp
pop ebx
};
The CPU has only a tiny bit of memory, the registers. You might also consider the L1 and L2 caches to be CPU memory, but those are controlled by the cache controller logic, you don't get any direct access unless you go mucking about in kernel code.
If you mean system RAM, that is where every variable you create in a program is "stored".
We need to clarify what you mean by "store". Storage is generally meant to be putting data on a non-volatile media, such as a hard drive or flash memory device.
The memory you use in RAM to hold data while a program is running is volatile, it doesn't persist after the program exits or the computer is shut down.
Can you allocate an array of 6MB in size? Sure. The simplest way is to make the array static, so it's not allocated on the stack. Or adjust the linker properties to provide a larger stack.
What the others said is true, but (with Linux/Unix at least) you can store stuff in RAM using shared memory. As vmanes said, it is volatile, in that when you reboot the system, it will be lost; however, it will be available as long as the system is running.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.