![]() |
![]() |
![]() |
#1 |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
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? |
![]() |
![]() |
#2 |
Total Chaos forever!
![]() |
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.
|
![]() |
![]() |
#3 |
Registered User
![]() Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 286
|
|
![]() |
![]() |
#4 |
Total Chaos forever!
![]() |
The buffered iostream routines are pulling in a lot more dependencies at link time.
|
![]() |
![]() |
#5 |
botcher
![]() Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 429
|
* don't use iostreams
* and if you don't use exceptions add -fno-exceptions |
![]() |
![]() |
#6 | |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
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? |
|
![]() |
![]() |
#7 |
ex. demoscener "Bigmama"
![]() Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,001
|
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. |
![]() |
![]() |
#8 | |||
botcher
![]() Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 429
|
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. |
|||
![]() |
![]() |
#9 | |
Natteravn
![]() Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,485
|
Quote:
|
|
![]() |
![]() |
#10 | ||
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
Yes, but this is a situation that is hard to handle anyway. ![]() 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? ![]() |
||
![]() |
![]() |
#11 | |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
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. |
|
![]() |
![]() |
#12 | |
Amigan
![]() Join Date: Feb 2012
Location: London
Posts: 886
|
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. |
|
![]() |
![]() |
#13 | |
botcher
![]() Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 429
|
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). |
|
![]() |
![]() |
#14 |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
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 |
![]() |
![]() |
#15 | |
botcher
![]() Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 429
|
Quote:
please unhide your command line / makefile |
|
![]() |
![]() |
#16 |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
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 |
![]() |
![]() |
#17 | |
botcher
![]() Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 429
|
Quote:
please use only one of -mcrt=nix13 -noixemul |
|
![]() |
![]() |
#18 |
Registered User
![]() Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 87
|
OK. Thanks! Then I stick to mcrt.
![]() |
![]() |
![]() |
#19 | |
Registered User
![]() Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 286
|
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. |
|
![]() |
![]() |
#20 |
Registered User
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 37
Posts: 3,401
|
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 | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
File Handling in BLitzmode | timeslip1974 | Coders. Blitz Basic | 4 | 10 September 2019 18:29 |
DOpus5 lister handling | daxb | Coders. Scripting | 0 | 05 December 2015 16:55 |
Program like NoFastMem but which forces all allocations to be MEMF_24BITDMA? | mark_k | request.Apps | 2 | 03 February 2013 21:54 |
Cookie handling | alexh | project.EAB | 1 | 22 October 2007 22:52 |
|
|