Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jose 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:
-
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.
-
... 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.
-
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
-
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:
-
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.
-
@Doobrey
Heck, I didn't knew that existed. Rules! I'll check it out as soon as I get home. :pint:
-
> 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).