Recent

Author Topic: SetLength() and memory checking  (Read 3852 times)

PeteS

  • New Member
  • *
  • Posts: 14
SetLength() and memory checking
« on: September 11, 2010, 07:48:48 am »
I've decide it's about time to pay attention to memory checking and potential runtime errors in a program I'm writing - to make it more robust and thus be able to share it with others.

I use dynamic arrays a lot, creating them with SetLength().  What is the best way to test whether I can actually safely create such an array? 

bflm

  • Jr. Member
  • **
  • Posts: 54
    • Free Pascal Random Bits
Re: SetLength() and memory checking
« Reply #1 on: September 11, 2010, 10:40:38 am »
I've decide it's about time to pay attention to memory checking and potential runtime errors in a program I'm writing - to make it more robust and thus be able to share it with others.

I use dynamic arrays a lot, creating them with SetLength().  What is the best way to test whether I can actually safely create such an array? 

IIRC, something like this (not tested)?
Code: [Select]
//...
  try
    SetLength(MyArray, SomeSize);
  except
    on E: EOutOfMemory do
      // recover or reraise or abort or ...
  end;
//...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: SetLength() and memory checking
« Reply #2 on: September 11, 2010, 06:29:02 pm »
Something like that, but only when sysutils is imported (otherwise RTE's are not converted to exceptions)

 

TinyPortal © 2005-2018