flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [SUG] free memory in W32 console to support batch operation

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 13 Apr 2010, 05:40
I have encountered a problem when running the console version. I keep running out of memory. Or at least it appears as though I have run out of memory, I actually have plenty of memory to compile with but I can't use it.

The reason is because the win32 console app does not free the memory when exiting. Of course Windows will free the memory eventually so there is no memory leak but Windows doesn't free the memory straight away.

I made a batch file to assemble all of my modules in with one command. It has this line: "for %%i in (*.asm) do fasmarm -m200000 %%~nxi" But the problem is every second file cannot be assembled due to lack of memory. The first file assembles fine and quits, the second file fails with a memory error, the third file assembles fine and quits, the fourth file fails with a memory error, an so on.

I fixed it with the following small addition to "SYSTEM.INC":
Code:
;...
exit_program:
      movzx   eax,al
      push    eax
 push    MEM_RELEASE             ;<----- add
      push    0                       ;<----- add
      push    [memory_start]          ;<----- add
      call    [VirtualFree]           ;<----- add
      call    [ExitProcess]
;...    
And naturally I had to add VirtualFree to the import table in FASM.ASM

After adding this additional code to free the memory I can do batch assembly without any problem.
Post 13 Apr 2010, 05:40
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 13 Apr 2010, 06:33
not freeing memory before exit is a serious flaw.
Post 13 Apr 2010, 06:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 13 Apr 2010, 08:20
That's another DOS legacy in work - since there memory was naturally freed on exiting, the interface (which was the base for all later ports) didn't have anything like that. Though, perhaps, if I knew that Win32 console works this way, I would have done something with this earlier.
Post 13 Apr 2010, 08:20
View user's profile Send private message Visit poster's website Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 843
Location: Jakarta, Indonesia
TmX 14 Apr 2010, 12:32
I applied this fix on FASM 1.69.13

Now every time I compile a program, FASM will crash.
But the program is compiled.

I'm on Windows 7, BTW.


Description:
Download
Filename: fasm.revolution.fix.zip
Filesize: 4.13 KB
Downloaded: 569 Time(s)

Post 14 Apr 2010, 12:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 14 Apr 2010, 13:14
TmX: You should use "push" not "call" -
Code:
  call [memory_start]  ;<----use PUSH    
Post 14 Apr 2010, 13:14
View user's profile Send private message Visit poster's website Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 843
Location: Jakarta, Indonesia
TmX 14 Apr 2010, 14:50
Ah silly me.
Now FASM runs fine.

Thanks Very Happy
Post 14 Apr 2010, 14:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 27 Apr 2010, 01:59
This patch is still needed for fasm 1.69.14

I have fixed it the the fasmarm v1.16 release.
Post 27 Apr 2010, 01:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 27 Apr 2010, 11:57
Since this is part of interface, not core, they fix doesn't require core version change. Thus I'm just updating the 1.69.14 package.
Post 27 Apr 2010, 11:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 27 Apr 2010, 12:03
Thanks for fixing. I don't mind making a few patches when each new version comes out, but when those patches get integrated into the official package it makes my life easier.
Post 27 Apr 2010, 12:03
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 27 Apr 2010, 12:12
Tomasz: I think that is the first time you have ever included one of my patches without any modification. Cool

I was expecting something like this:
Code:
 movzx   ebx,al
      push    MEM_RELEASE 0 [memory_start]
        call    [VirtualFree]
       push    ebx
 call    [ExitProcess]    
Because the 'push eax' above is rather hacky coding since it is not used until after the VirtualFree. I usually just makes these patches hastily, knowing you will want to "make them your own" anyway. So I don't go much further than making it just work and leave it there for the master to make the proper adjustments.
Post 27 Apr 2010, 12:12
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 27 Apr 2010, 12:17
Well, this time I really liked it the way it was. Smile
Post 27 Apr 2010, 12:17
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.