Welcome, Guest. Please login or register.

Author Topic: Saving to HD with almost zero free memory possible ?  (Read 2132 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Saving to HD with almost zero free memory possible ?
« on: February 02, 2006, 06:34:52 PM »
Hi. Is there a way to save data to HD or send it over a network when there is an out of memory error or there's no way around it ? The goal is to be able to save a log of errors that happened during program execution but if the error is out of memory and memory is close to zero (maybe not even enouph for a file handle ?)I guess there's not much you can do.
My own solution would be to have a contantly open file to save to, so that the system doesn't have to allocate memory for the file lock.
Any other suggestions on how to handle this...?

:pint:
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Zac67

  • Hero Member
  • *****
  • Join Date: Nov 2004
  • Posts: 2890
    • Show only replies by Zac67
Re: Saving to HD with almost zero free memory possible ?
« Reply #1 on: February 02, 2006, 06:56:16 PM »
Or you monitor free RAM and when it falls below a certain threshold, you trigger the save (provided the rest isn't gone at once).
Another method could be to allocate a sufficient amount of memory, wait for the out of mem error, free the reserved mem and save as quickly as possible.
Everything depends on how RAM is consumed; little by little or large chunks at once.
 

Offline platon42

  • Hero Member
  • *****
  • Join Date: Jul 2002
  • Posts: 573
    • Show only replies by platon42
    • http://www.platon42.de/
Re: Saving to HD with almost zero free memory possible ?
« Reply #2 on: February 02, 2006, 07:24:37 PM »
... or, of course, you could allocate some memory before and write a low memory handler that would free the memory on a low memory situation and right after that would write a log report to disk (and hopefully, the memory you freed would ensure a stable system to write the file back to disk (I believe this operation won't use much memory, if any at all)).

But beware, low memory handlers are also triggered by "avail flush" aka flushlibs.
--
Regards, Chris Hodges )-> http://www.platon42.de <-(
hackerkey://v4sw7CJS$hw6/7ln6pr7+8AOP$ck0ma8u2LMw1/4Xm5l3i5TJCOTextPad/e7t2BDMNb7GHLen5a34s5IMr1g3/5ACM
 

Offline Hyperspeed

  • Hero Member
  • *****
  • Join Date: Jun 2004
  • Posts: 1749
    • Show only replies by Hyperspeed
Re: Saving to HD with almost zero free memory possible ?
« Reply #3 on: February 02, 2006, 08:00:01 PM »
I had the same trouble yesterday. IBrowse2.3 was doing something that ate limitless amounts of memory due to some glitch and it left me with a few bytes of ChipMem to save work. With such little memory you can't open a requestor - so you're done for.

MultiCX allows you to define a 'Ctrl-Alt F' for flushing memory but you'll rarely gain more than a few K.

Is there no way of leaving a browser window open and having that close/iconify when memory is tight, or even filling Ram Disk: with a large dummy file, deleting it when required?

I like this program:
ftp://de.aminet.net/pub/aminet/util/moni/ShowMem.lha
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Saving to HD with almost zero free memory possible ?
« Reply #4 on: February 02, 2006, 08:14:39 PM »
That's great (reserving a big enouph chunk for my program when it launches) but the problem is that it allocates memory dynamically. Sometimes it needs more, sometimes less, so I'd have to write my own "internal allocator". Never tried it, myabe it's not that difficult.. (another bunch of time with something not predicted...:getmad:))

For the error log I think I'm just gona leave a file constatly open and just try to save an error code.  

:pint:
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Doobrey

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 1876
    • Show only replies by Doobrey
    • http://www.doobreynet.co.uk
Re: Saving to HD with almost zero free memory possible ?
« Reply #5 on: February 02, 2006, 09:10:51 PM »
Quote

Jose wrote:
...so I'd have to write my own "internal allocator". Never tried it, myabe it's not that difficult.. (another bunch of time with something not predicted...:getmad:))


If you're using OS 3.0+ there's CreatePool/AllocPooled/FreePooled/DeletePool that'll save you having to write your own.
On schedule, and suing
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Saving to HD with almost zero free memory possible ?
« Reply #6 on: February 02, 2006, 09:14:32 PM »
@Doobrey

Heck, I didn't knew that existed. Rules! I'll check it out as soon as I get home. :pint:
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline platon42

  • Hero Member
  • *****
  • Join Date: Jul 2002
  • Posts: 573
    • Show only replies by platon42
    • http://www.platon42.de/
Re: Saving to HD with almost zero free memory possible ?
« Reply #7 on: February 02, 2006, 11:07:24 PM »
> That's great (reserving a big enouph chunk for my program when it launches) but the problem is that it allocates memory dynamically.

That's not what I meant. The memory I'm talking about that is allocated at start is meant to be a "last resort" memory for *other* programs (as it is supposed to be freed by the low memory handler (see exec/AddMemHandler() for details), and signals your main task to panic, and save the errorlog to disk).

About dynamic memory, I strongly suggest you're using memory pools (as others already mentioned it).
--
Regards, Chris Hodges )-> http://www.platon42.de <-(
hackerkey://v4sw7CJS$hw6/7ln6pr7+8AOP$ck0ma8u2LMw1/4Xm5l3i5TJCOTextPad/e7t2BDMNb7GHLen5a34s5IMr1g3/5ACM