1

I am developing a 32 bit application and got out of memory error.

And I noticed that my Visual Studio and a plugin (other apps too) used too much memory which is around 4 or 5 GB.

So I suspected that these program use up all the memory addresses where my program is able to find free memory.

I suppose that 32 bit can only use the first 4 GB, other memory it can not use at all.

I don't know if I am correct with this, other wise I will look for other answers, like I have bug in my code.

Niall
  • 30,036
  • 10
  • 99
  • 142
cHiWa
  • 383
  • 1
  • 3
  • 14
  • 1
    A 32-bit program can't address more than 4GB, and depending on operating system the actual limit may be lower than that. Also, all memory allocations are contiguous and if there's no big enough chunk of memory available then you get out errors too. – Some programmer dude Sep 16 '14 at 08:38
  • 2
    @JoachimPileborg: Contiguous in virtual space, not in physical space - important distinction. – Mats Petersson Sep 16 '14 at 08:44
  • 1
    Note that the 32bits address space in 64bits windows is a virtual address space offering up to 4Gb of addressable memory locations, which are on demand mapped by the OS page-by-page to physical RAM and/or memory mapped files. The physical RAM pages don't have to be contiguous, other programs/processes don't reduce the virtual address space of your 32 bit application unless it calls in-process services or in-process plugins. – Maarten Hilferink Sep 16 '14 at 08:47
  • I was assuming your application is generating the out of memory error, but now i wonder why. Could you be more specific on the error you got? – Maarten Hilferink Sep 16 '14 at 08:51
  • To be specific, I have DirectX program, when I call IDirect3DSwapChain9::Present and it returns E_OUTOFMEMORY, while my application only used 50 mb memory. – cHiWa Sep 16 '14 at 08:59
  • From your question,, it is not clear, if you reach the per application memory limit or the system memory limit. In the second case, you should be aware that usable memory is a matter of licensing on 64 bit MS Windows. (Of course a 32 bit application cannot address more than 4GB) – Jakub Sep 16 '14 at 10:13
  • It is also possible that you get out-of-memory for some resource that isn't just basic memory, but for example some resource that was allocated at startup - in other words, "out of memory" doesn't REALLY mean that "there is no memory in the system", but that "we ran out of memory for this operation" - a lot of drivers and libaries have allocations are are a fixed size and aren't allowed to grow. – Mats Petersson Sep 16 '14 at 21:27

2 Answers2

4

Your statement of

I suppose that 32bit can only use the first 4 giga byte, othere momery it can not use at all.

is definitely incorrect. In a 64-bit OS, all applications can use all of the memory, regardless of what bitness it is, thanks to the translation table for virtual to physical memory being 64-bit.

Some really ancient hardware may not allow DMA to addresses above 4GB, but I really hope most of that is in the junk-yard by now.

If the system as a whole is running low on memory, it will affect all applications more or less equally.

However, a 32-bit application can only, by default, use the lower 2GB of the virtual address range (although these 2GB can be placed anywhere in the physical memory, as described above by means of a 64-bit translation table). You can extend this to nearly 4GB (3GB in a 32-bit OS, and subject to the /3GB boot flag in this case) by using /LARGEADDRESSAWARE in your linking command - this simply tells the OS that your application will "understand" that addresses can be negative, and thus will operate correctly with addresses over 2GB.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • DMA isn't used by processes directly, at least not on any 64 bit OS targeted by Visual Studio (i.e. Windows). So that's mostly an OS problem; it may need to copy memory before DMA output or after DMA input. Also, I don't think that addresses are ever negative on Windows. In particular, if you get a memory block from 0x7FFF0000 to 0x8001000, `end>begin` still holds. – MSalters Sep 16 '14 at 08:52
  • Just a note, but your comments really only apply to Windows. A 32 bit application under Solaris can access 4GB, and under Linux, IIRC, a good deal more than 2GB (but not the full 4GB); neither has a `/LARGEADDRESSAWARE` option either. – James Kanze Sep 16 '14 at 09:44
  • Since the OP maintains that ["my application only used 50 mb memory"](http://stackoverflow.com/questions/25864105/is-it-true-that-32bit-program-will-be-out-of-memeory-if-other-programs-use-too/25864247#comment40472910_25864105), the OP's selection of this answer as a solution is baffling to say the least. There is nothing at all here that addresses how to solve the OP's issue. Of course, the OP's question does not give any pertinent information either. – Cheers and hth. - Alf Sep 16 '14 at 10:48
0

Any system can be brought down by a too heavy load.

But in normal use in Windows and any other virtual memory OS, the memory consumption of other programs does not much affect any given program execution.

Getting an out of memory error is unusual, but it can happen if you make a large allocation or if you declare a large local automatic variable. It can also happen if you fail to properly deallocate memory that's no longer used, i.e. if the program is leaking memory. For a 32-bit program on a 64-bit machine it's then not memory itself that's used up, but available address space within the program.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331