Emulator vs SDL_APP_LOWMEMORY?

Emulation of old PCs, PC hardware, or PC peripherals.

Emulator vs SDL_APP_LOWMEMORY?

Postby superfury » 2017-11-28 @ 06:20

Do emulators have to do something when SDL_APP_LOWMEMORY is received? Since all allocations are used all the time? Flush all memory allocated to disk and reallocate on becoming active again(standby mode), otherwise terminate?
superfury
l33t
 
Posts: 2679
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby BloodyCactus » 2017-11-28 @ 13:27

Thats the OS giving you a hint that you should do something. This comes from Android/IOS when you pause or leave the app (but its still running) and you should release resources back to the OS.

Check the "README-IOS.TXT" for more explanation.
--/\-[ Stu : Bloody Cactus :: http://kråketær.com :: http://mega-tokyo.com ]-/\--
User avatar
BloodyCactus
Oldbie
 
Posts: 733
Joined: 2016-2-03 @ 13:34
Location: Lexington VA

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby superfury » 2017-11-28 @ 14:12

So what CAN I do without losing any emulation data? Everything that's allocated is mostly RAM blocks containing emulation states(VGA VRAM, video rendering helper data allocated through SDL2, precalculation tables used for various hardware and emulated RAM memory containing all emulated stuff(so everything the PC uses to run, like emulated RAM, ROM etc.))

What stuff should be written to disk (and read back when becoming active again)?
superfury
l33t
 
Posts: 2679
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby BloodyCactus » 2017-11-28 @ 14:30

your app is a guest, so you should put everything you can on disk, etc, removed from ram. if the user hits the phone button and your app does nothing with all its memory then the user cant make a call. your app has zero importance compared to anything else.

if you loose emulation data, then you loose it.

read more up on android/ios development and memory handling, state and backgrounding.

you'd get better advice on a real mobile dev oriented forum than here.
--/\-[ Stu : Bloody Cactus :: http://kråketær.com :: http://mega-tokyo.com ]-/\--
User avatar
BloodyCactus
Oldbie
 
Posts: 733
Joined: 2016-2-03 @ 13:34
Location: Lexington VA

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby Dominus » 2017-11-28 @ 16:58

You should know yourself best what your emulator needs to get back on track.
Correct behavior of your emulator should be to dump some kind of savestate when entering background (there is an SDL event for that as well). Because you don't know when the user just closes the background app OR when the OS decides that your app is hogging too much memory (well you know when that event is triggered) and soon autocloses it.
User avatar
Dominus
DOSBox Moderator
 
Posts: 7691
Joined: 2002-10-03 @ 09:54
Location: Ludwigsburg

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby superfury » 2017-11-28 @ 19:31

IF I modify it to dump all dynamically allocated data to disk, can a foreground event(SDL_APP_SIDENTERFOREGROUND) be assured to reallocate all those? So up to 64MB(autodetected using malloc, I usually limit it to 4MB) RAM buffer as well as 1MB video memory, VGA VRAM(256k) and various hardware emulation buffers(up to 50000 16-bit samples for each channel, precalcs for audio resampling, video resizing precalcs(horizontal and vertical for each source SDL surface(wrapper around SDL_Surface object) and other small buffers)?
superfury
l33t
 
Posts: 2679
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby Dominus » 2017-11-28 @ 19:51

Again, this is up to you. All the OS is doing is reporting that you are back in foreground. Your app needs to make sure it reacts appropriately
User avatar
Dominus
DOSBox Moderator
 
Posts: 7691
Joined: 2002-10-03 @ 09:54
Location: Ludwigsburg

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby superfury » 2017-11-28 @ 20:00

Like I said, if I store that data(up to 100MB+) in files and free the memory. Then if I reallocate the memory using malloc during SDL_APP_DIDENTERFOREGROUND, will the reallocation(up to ~100MB+ previously freed) always succeed? Is it possible for the malloc(reallocating those buffers) to fail? If it can fail reallocating when restoring state(same memory the app originally used before the low memory event), it can and WILL crash, because all those buffers in their original size and data are required for the application to function without errors or memory shortage. ? If it can't reallocate, my app can and WILL fail because all allocated buffers contain data required for normal operation of the emulator and input/output.

It's 67.8MB according to Android's maintenance information. That's the basic XT with AweROMGM soundfont and VGA emulation with 1MB RAM autodetected(limited to 4MB(max 64MB) on AT+).
Last edited by superfury on 2017-11-28 @ 20:08, edited 1 time in total.
superfury
l33t
 
Posts: 2679
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby Dominus » 2017-11-28 @ 20:05

Just try it or use the ever giving Stackoverflow to get better answers :)
You may just need to make sure in your code that what you saved is all loaded back and if not gracefully exit.
User avatar
Dominus
DOSBox Moderator
 
Posts: 7691
Joined: 2002-10-03 @ 09:54
Location: Ludwigsburg

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby vladstamate » 2017-11-28 @ 20:09

superfury wrote:Like I said, if I store that data(up to 100MB+) in files and free the memory. Then if I reallocate the memory using malloc during SDL_APP_DIDENTERFOREGROUND, will the reallocation(up to ~100MB+ previously freed) always succeed?


No. There is a big chance you will not be able to re-alocate. And yes, you will have to crash. Because another (misbehaved) application did not release its memory so the OS has not space for your allocations.

I know nothing about Android but in iOS there is no paging or virtual memory support. Whatever is available physically it is all there is. The memory will not grow to allow the foreground app to allocate whatever it needs. Which is why it is designed to send you messages like SDL_APP_LOWMEMORY. On mobile devices memory is much more of a physical barrier than on PCs due to lack of virtual management.
User avatar
vladstamate
Oldbie
 
Posts: 871
Joined: 2015-8-23 @ 01:43

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby superfury » 2017-11-28 @ 21:51

So in other words: I'll have to redirect SDL_APP_LOWMEMORY to SDL_APP_TERMINATING, to let the main thread(and the other threads) tear the emulator down, save progress(BIOS Settings containing CMOS state) and quit the app?
superfury
l33t
 
Posts: 2679
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: Emulator vs SDL_APP_LOWMEMORY?

Postby BloodyCactus » 2017-11-28 @ 22:38

no, save everything and acknowledge the message. when it comes back, if you cant allocate memory, just pop up an error box saying not enough memory. you already have saved state, so if your app restarts clean later, it just reloads state. no big deal.
--/\-[ Stu : Bloody Cactus :: http://kråketær.com :: http://mega-tokyo.com ]-/\--
User avatar
BloodyCactus
Oldbie
 
Posts: 733
Joined: 2016-2-03 @ 13:34
Location: Lexington VA


Return to PC Emulation

Who is online

Users browsing this forum: No registered users and 0 guests