flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Liebranca 23 Sep 2023, 01:35
Hello,
I wrote this awful bit forever ago to conditionally include files. It works, but it uses a lot of memory, and much more for each level of recursion. So, my question: can you estimate the memory cost of a complex chain of directives? I'm confident I can optimize this solely using intuition, but if there's any hard rules that would also help ;> Cheers. |
|||
![]() |
|
Liebranca 24 Sep 2023, 15:35
I wound up fixing the problem a few hours after making this post, the issue was (for the better part) caused by nested matches, within rept, within a forward block.
That bit was needed to pop from the list of files to include, but since I rewrote most of the importer macros, I was left with shorter code and lists that took less steps to break up, so I was able to simplify the loop as well. Now it's light as a feather. I tested by forcing fasm to assemble some files using only 256~ KB, done with no trouble. Moral of the story: it's always best to do less work ;> On an unrelated note, I believe I was using purge a lot in another file that's been giving me problems lately, so maybe I should look into that next. |
|||
![]() |
|
Tomasz Grysztar 24 Sep 2023, 16:43
revolution wrote: Another minor thing I discovered is that using purge increased memory usage slightly, but not significantly. That is, the purge doesn't recover used memory allocations, it just unlinks the memory or marks it invalid, or similar, so the purge line itself uses the extra space in memory. A definition of a macro is a simple structure that contains a pointer into the preprocessed source - to the text of the macro definition. So when you "purge" such macro, you actually free the structure that contains the pointer, but this recovers very little memory, while the preprocessed text that was pointed to stays where it was, as it is just a section of the complete preprocessed source text that is kept indefinitely. This is why adding a "purge" does not decrease memory usage - because the amount of memory that is recovered is small compared to the length of the line containing "purge" command being added to preprocessed source. The header of a preprocessed line is 4 dwords already, and it's followed by the preprocessed tokens, giving another dozen bytes at the very least. PS. To be precise, the memory recovered by "purge" is not actually freed in a general sense, it only becomes available to be re-used when you define the macro again. But here this is a less consequential detail - even if this memory was truly made available to be used for any purpose, it would still be not enough to offset the loss caused by adding another line to the preprocessed text. |
|||
![]() |
|
revolution 24 Sep 2023, 18:17
I needed 10kB more memory to assemble with purge than without.
With purge: Code: ~ cat purge.asm ; echo ; fasm purge.asm -m 73 rept 999 { purge a macro a \{\} } flat assembler version 1.73.31 (73 kilobytes memory) error: out of memory. ~ cat purge.asm ; echo ; fasm purge.asm -m 74 rept 999 { purge a macro a \{\} } flat assembler version 1.73.31 (74 kilobytes memory) 1 passes, 0 bytes. Code: ~ cat no_purge.asm ; echo ; fasm no_purge.asm -m 63 rept 999 { macro a \{\} } flat assembler version 1.73.31 (63 kilobytes memory) error: out of memory. ~ cat no_purge.asm ; echo ; fasm no_purge.asm -m 64 rept 999 { macro a \{\} } flat assembler version 1.73.31 (64 kilobytes memory) 1 passes, 0 bytes. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.