Recent

Author Topic: Running my code consumes too much RAM memory my computer doesn't have  (Read 2465 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: 696
    • 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

  • New Member
  • *
  • Posts: 20
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: 931
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 »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

dbannon

  • Hero Member
  • *****
  • Posts: 2022
    • 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 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Thaddy

  • Hero Member
  • *****
  • Posts: 11517
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 »
Путин преступник. Россияне дезинформированы.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 853
  • 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 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.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