22 September 2019, 21:15 | #1 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Handling dynamic memory allocations
Programming for a classic Amiga is quite different than on more modern machines. Obviously memory size plays a much stronger role, because of the more limited memory and of course thetr is also the issue of differentiating between chip and fast memory.
So when using a toolchain like gcc, how do you tackle the problem? Do you avoid using std containers? Vector is rather useful but the standard implementation is probably a bit problematic when writing more complex programs. I did some test and when I was using the std::string class the size of my executable was jump from 20kb to whooping 170kb, which is quite a lot. So I assume that I have to do my own memory handling and avoid using the std containers? Or how do you deal with that? |
22 September 2019, 21:36 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
Bebbo is trying to get GCC to use NewLib as its C runtime. Aros already has an ArosC.library in its kernel. Using template specialization to wrap LibStdC++ runtimes might help in the future.
|
23 September 2019, 00:33 | #3 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,546
|
|
23 September 2019, 00:50 | #4 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
The buffered iostream routines are pulling in a lot more dependencies at link time.
|
23 September 2019, 12:07 | #5 |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
* don't use iostreams
* and if you don't use exceptions add -fno-exceptions |
23 September 2019, 13:08 | #6 | |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
It depends. An Amiga 1000 has (usually) 512kb, which is not much. Fresh from the factory it even has only 256kb but I guess that not many people actually use it as such. So developing a game I would think that I rather use the memory for gfx and sound instead of io routines. Anyway, I was just experimenting, to see how much overhead certain things will add. For example, using "new" instead of "malloc" also adds 70kb of additional size, which I also didn't expect. When I created a barebone binary it had about 350bytes, using "printf" it increases to 20kb, which is IMO acceptable, because it's needed for debugging purposes. string functions are convenient, but considering the overhead I wouldn't use them for game code. Quote:
Does "no-exception" disable any exception or only prevents the standard functions not throwing? So when I throw and catch within my own code, this would still work, or is it also disabled? |
|
23 September 2019, 13:39 | #7 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
If you're using gcc, you can use stuff like "-ffunction-sections" and "--gc-sections" to have the linker through out unused code - this will likely reduce your executable size.
Link time optimization ("-lto") may help further. |
23 September 2019, 15:35 | #8 | |||
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
Quote:
new throws an exception by default if the memory is exhausted. Quote:
You aren't using the -noixemul option. Quote:
Guess the the exception stuff get's linked plus it won't work, since the startup does not initialize it properly. |
|||
23 September 2019, 16:02 | #9 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
|
|
23 September 2019, 16:09 | #10 | ||
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Yes, but this is a situation that is hard to handle anyway. And if memory gets exhausted, there is not much I can do about it, so it doesn't matter if the game crashes. Quote:
What does this do? Is there some overview about all these options and when to use them? Quote:
Well, if it is linked anyway, then this option doesn't make much sense, right? |
||
23 September 2019, 16:13 | #11 | |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Quote:
Currently I'm only experimenting with the memory, so these are just findings, that I consider interesting. I don't really want to work with plain C, because C++ adds a lot of other stuff, which is useful and convenient. So knowing the limitations, I can take advantage of the C++ features that I want and can still fall back in some cases if it is necessary. I prefer C++ because of it's inherent typesafety objects and overloading, which IMO makes the code much clearer. Also templates can be very useful, so all in all, even if one can not use the full feature set of an advanced C++ compiler, IMO there is enough benefit to still use it. |
|
23 September 2019, 19:25 | #12 | |
Amigan
Join Date: Feb 2012
Location: London
Posts: 1,309
|
Quote:
ixemul is a POSIX compatibility layer. It lets you easily port Unix style software. The downside is that it's quite memory hungry and sometimes drops Amiga conventions for compatibility. It was originally part of the GeekGadgets project (as was GCC) which includes all the userland tools that you would normally find on Linux/BSD etc. This includes things like X Windows. I've had GIMP running on my Amiga. |
|
23 September 2019, 21:22 | #13 | |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
Quote:
my gcc toolchain is using a newlib implementation as default, since the ixemul.library did not build that easily... (if someone provides a working build for my toolchain, I'll add it back - maybe even as default) and that newlib yields larger executables than libnix (aka -noixemul). |
|
23 September 2019, 21:41 | #14 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
When I add " -noixemul" then I get an error:
Code:
/opt/amiga/bin/m68k-amigaos-ld: E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:(.text+0x64): multiple definition of `_exit'; E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:(.text+0x64): first defined here c |
24 September 2019, 19:36 | #15 | |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
Quote:
please unhide your command line / makefile |
|
25 September 2019, 18:46 | #16 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Code:
m68k-amigaos-g++.exe --save-temps -Wall -pedantic -mcrt=nix13 -O3 -DNDEBUG -noixemul CMakeFiles/testing.dir/main.cpp.o -o ../bin/testing.exe -Wl,--out-implib,../bin/libtesting.dll.a -L/d/src/amiga/projects/testing/../lib/Release -lutils /opt/amiga/bin/m68k-amigaos-ld: E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:(.text+0x64): multiple definition of `_exit'; E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:E:/Programme/msys64/opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o:(.text+0x64): first defined here collect2: error: ld returned 1 exit status |
26 September 2019, 20:30 | #17 | |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
Quote:
please use only one of -mcrt=nix13 -noixemul |
|
27 September 2019, 07:09 | #18 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
OK. Thanks! Then I stick to mcrt.
|
28 September 2019, 06:10 | #19 | |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,546
|
Quote:
Back then we were acutely aware of code bloat and went to great lengths to reduce it. I even wrote my own startup code and printf replacement. Today I don't worry about it so much. Anyone who has less than 1MB should get an upgrade. |
|
28 September 2019, 12:21 | #20 |
Registered User
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,772
|
Having more memory isn't an excuse to write shit code. Are you sure you don't work for Microsoft?
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
File Handling in BLitzmode | timeslip1974 | Coders. Blitz Basic | 4 | 10 September 2019 17:29 |
DOpus5 lister handling | daxb | Coders. Scripting | 0 | 05 December 2015 15:55 |
Program like NoFastMem but which forces all allocations to be MEMF_24BITDMA? | mark_k | request.Apps | 2 | 03 February 2013 20:54 |
Cookie handling | alexh | project.EAB | 1 | 22 October 2007 21:52 |
|
|