Still worrying about memory usage, and loving it!
One of the things that comes from having cut my teeth on early micro computers was that I always, but always, had to worry about memory usage. When your computer's got 4KB RAM, as had my 1st Tandy TRS80 Model I, you have to worry about code being small enough to fit and to leave enough room for data.
Later I was constraining the size of my programs due to the time it took to upload them on my dial up internet connection.
Even now I still can't stop worrying about profligate use of memory or disk space.
I've resigned myself to the inefficiencies or bloatware, but there are still some marvellous examples of coding efficiency out there. My favourite example is my Digital Audio Workstation of choice, REAPER. It's a professional quality, complex application with a download size of 15Mb (for the latest Win 64 v6.72 as of December 2022). That's not a typo - it's 15Mb. And no, it's not for a downloader that scuttles off to the net to get the main program. That's the full application. I've got simple apps on my phone bigger than that.
Back in my happy place
Just recently I've discovered the fun that can be had programming microcontrollers. And guess what, the older ones have RAM measured in kilobytes. The Arduino Nano clone pictured below has 2KB of static RAM and 32KB of flash (EEPROM) memory. Others, like the ATTiny85, have even less. I'm feeling right at home!
There's always a downside though. This type of microcontroller usually has to be programmed in C or C++ 👿. Bugger.
Is there anyone else out there who still has the old memory conservation fetish? Do you have the desire to declare all Pascal records as packed, because, well, they're smaller?
I only declare records as packed to have defined size and field offsets so they can be written to and read from files independently of programming language. Memory usage usually doesn't enter the equation with most programs. It's cheap and it's there (I'm talking about Windows programs here, mind you.)
ReplyDeleteThere are a few exceptions, e.g. our tool for displaying various kinds of maps is one because that data can become huge, so recently I changed it from using lists of objects for storing coordinates (x,y: double) to using arrays of records. That reduced the memory consumption and fragmentation(!) significantly and on top of that also made it significantly faster.
Interesting that changing from objects to records speeds things up as well saving memory.
DeleteThese days I really only declare packed records for the same reason as you, or for any API calls that need them, but the itch is still there to do it!
Free Pascal supports programming for AVR based micro controllers (see https://wiki.freepascal.org/AVR_Programming ), ARM based micro controllers like the STM32 and Raspberry Pi Pico (see https://wiki.freepascal.org/ARM_Embedded_Tutorials ) or Xtensa based ones like the ESP32 and ESP8266 (see https://wiki.freepascal.org/Xtensa ). So you are not required to program in C or C++ if you want to work with Pascal instead. ;)
ReplyDeletePlease note that declaring records as packed might have a negative impact on performance depending on the hardware. E.g. on older ARM chips the compiler needs to do Byte-by-Byte access if the fields aren't aligned correctly.
Wow. Didn't know that FPC compiles for all those microcontrollers - I use Arduino clones, ATiny, RPi Picos and both ESP types. Will be checking out those links ASAP. Thx a lot for that.
DeleteI don't usually pack records these days to be honest (unless required for an API call) - but I always feel the itch!