Recent

Author Topic: Running my code consumes too much RAM memory my computer doesn't have  (Read 3215 times)

eli

  • New Member
  • *
  • Posts: 33
I have written a code in Free Pascal, but when I tried to run it in my computer, the computer collapsed, because its RAM memory is limited (Actually 3 GB, 64 bits). Is there any website, having sufficient RAM memory, where I can - both send my code (which includes no "read" instructions) - and receive the output?
« Last Edit: November 06, 2021, 09:38:45 pm by eli »

Laksen

  • Hero Member
  • *****
  • Posts: 754
    • J-Software
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #1 on: November 06, 2021, 09:53:21 pm »
You can probably spin something up at AWS or one of the other large cloud providers. But it probably won't be cheap

Maybe a cheaper option would be to restructure your program to not need that much ram simultaneously?

Jorg3000

  • Jr. Member
  • **
  • Posts: 64
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #2 on: November 06, 2021, 10:11:45 pm »
Do you even know why your program needs more than 3 GB of memory?
Did you forget to free unused objects or is the memory requirement intentional?

eli

  • New Member
  • *
  • Posts: 33
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #3 on: November 07, 2021, 12:46:08 am »
Well, actually my program needs a three dimensional array of the size 2 X 4096 X 4096. The array contains integers in the range 0...1681.

Additionaly, my program needs a two dimensional array of the size 2 X 4096. The array contains pseudo-integers of the type: MpInteger, as defined in Gmp unit.

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #4 on: November 07, 2021, 01:42:09 am »
hi
the 3 dimensional array should take about 67mb when using int16;
what is the size in bytes of mpinteger ?

are your arrays dynamic?
« Last Edit: November 07, 2021, 01:57:03 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

dbannon

  • Hero Member
  • *****
  • Posts: 2802
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #5 on: November 07, 2021, 05:36:05 am »
the 3 dimensional array should take about 67mb when using int16;
what is the size in bytes of mpinteger ?

Yep, while eli's code is likely to be 32bit integer (objfpc mode) we are still going to be struggling to use anything like 3Gig. Declariing them as smallint would help...

I have no idea what mpjntegers are but lets assume (for fun) they are 512bits, the second array is using 4Meg.

No, sorry eli, its got to be a coding issue, not a memory one.

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #6 on: November 07, 2021, 06:43:39 am »
Code: Pascal  [Select][+][-]
  1. uses windows;
  2. {$SetPeFlags(IMAGE_FILE_LARGE_ADDRESS_AWARE )}// is $0020
For 32 bit code on windows gives you at least 4Gb addressable space for a 32bit program on win64 and a maximum of 3GB on win32. But slightly less will be available because of processes and programs. See msdn.
If that is still not enough buy more memory. (Or use the overlapped file API)
« Last Edit: November 07, 2021, 07:02:21 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1122
  • Professional amateur ;-P
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #7 on: November 07, 2021, 07:16:09 am »
Hey eli,

Ok, let's do some maths: 2*4096*4096 = 33'554'432 Cells

Let's assume were doing 64b integers: 33554432*64 = 2'147'483'648 bits = 268'435'456 bytes = 256 MB

That's nowhere near 3GB since its only a quarter of a Gig. On that amount of RAM you can have 12 of those matrices, well less since you do need the OS to be running.

And with the second matrix, like Davo mentioned, even with 512 bit integers, that would be only 4MB.

So, it's definitely nothing to do with memory but everything to do with the way you're manipulating that memory.

I'm unaware of how the GMP unit uses those MpIntegers, so I'm not really comfortable blaming the GMP unit just yet.

But, if you're running Windows on a 3GB system, well, how much RAM do you really have free, I wonder. I'm guessing that you have at least some 300MB of spare RAM to run the code and allocate the data space.
If you're able to have Lazarus open and running the code, I'm guessing your system can spare the 300MB...

So, again, back to how your code is manipulating that data.

If you would provide us with a test project, or a subset of your code so we can have a better look at how it's running, maybe we could me of more help.

Hope that helps!!

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

eli

  • New Member
  • *
  • Posts: 33
Re: Running my code consumes too much RAM memory my computer doesn't have
« Reply #8 on: November 07, 2021, 11:29:11 am »
Solved!

Thank you all. It seems you are right.

The problem stemmed from the way MpIntegers are to be treated. Actually, MpInteger is a Type of whole numbers having no bound (up to the RAM memory). They are treated well by Gmp unit, with all the useful arithmetical operations. However, when treating them, one must be careful with the operation of assignment, which is not as simple as I thought when I was running my code.

So yes, it was not the RAM memory that made my computer collapse. Anyway, it's okay now. Cheers!
« Last Edit: November 07, 2021, 09:26:29 pm by eli »

 

TinyPortal © 2005-2018