Page 1 of 1

Custom Emulator for Steam release of Homebrew

Posted: Fri Oct 23, 2020 6:25 am
by gravelstudios
I mentioned in another thread that I'm building a custom emulator using MonoGame framework and C# in which to package my game rom for release on platforms like Steam that require the game to be a standalone exe file. After about a week of work, I have it running (not counting APU, I'm just going to import the audio files for music and sound effects). Thought I'd share a thought for anybody just starting out in programming.

I was checking task manager and noticed that my emulator was using 1.5 Gb of RAM. that's an awful lot considering what I was doing. Long story short, if any object has a Dispose() method, either use it, or put it in a using block. Finding an object that I wasn't disposing of and fixing it dropped my memory usage down to 35 Mb.

Re: Custom Emulator for Steam release of Homebrew

Posted: Sun Oct 25, 2020 6:51 pm
by Uvixen
gravelstudios wrote:
Fri Oct 23, 2020 6:25 am
I was checking task manager and noticed that my emulator was using 1.5 Gb of RAM. that's an awful lot considering what I was doing. Long story short, if any object has a Dispose() method, either use it, or put it in a using block. Finding an object that I wasn't disposing of and fixing it dropped my memory usage down to 35 Mb.
That's C#/.NET 101.

What IDE are you using? I thought Visual Studio 2019 had warnings for forgetting to dispose of objects, but maybe that's the SonarLint extension I have installed.

Re: Custom Emulator for Steam release of Homebrew

Posted: Mon Oct 26, 2020 4:54 pm
by gravelstudios
Visual Studio 2017 community. short version: I got some code off of Stack Overflow for using a Texture2D and passing a Color array to it to draw my screen. I didn't notice that I had to Dispose the Texture2D on each frame. so my emulator was basically hanging onto each frame of video until the garbage collector happened to get around to deleting it. Not very efficient.

Re: Custom Emulator for Steam release of Homebrew

Posted: Mon Oct 26, 2020 11:21 pm
by Dwedit
Shouldn't really be allocating a new texture every frame, instead you should update the texture.

Re: Custom Emulator for Steam release of Homebrew

Posted: Tue Oct 27, 2020 5:01 am
by gravelstudios
Dwedit wrote:
Mon Oct 26, 2020 11:21 pm
Shouldn't really be allocating a new texture every frame, instead you should update the texture.
Yes, that had occurred to me also.