I’m working on porting my own little archiving program to Haiku (zpaqfranz).
I’m having some problems, but I think it can be solved
I would need help with a specific function though, which basically returns the current free RAM (or an estimate of it)
The environment is normal g++
Basically it is used to allocate (almost) all the available RAM to extract deduplicated files and recalculate the relative hashes (short version), instead of a filesystem temporary path
/*
This function is rather tricky: report the "just about free" memory of the system.
It depends on both the operating system and the compiler (and architecture)
It is needed for the -ramdisk switch
If you have compiling problems, for example because you are using a "strange" system,
just change the source code to return 0;
As today tested on (64 bit)
- Windows
- FreeBSD
- OpenBSD 6.6/7.1
- Debian
- Solaris 11
- OmniOS
- MacOS 11
*/
#ifdef __HAIKU__
int64_t internal_getramdisksize()
{
myprintf("Haiku!\n");
return 0;
}
#endif
I suppose there’s documentation for it somewhere, but it’s not that easy to find (at least for a newbie)
Thanks for every answer!
PS does some kind of “pkg install zpaqfranz” esists in Haiku?
Also please be aware that in most modern OSs free memory can change from one moment to the next one. There’s more memory available to a process than there is physical memory! This is called virtual memory.
For example if you have two large chunks of memory used by your program but they are not used simultanously, you (or the OS) could swap them.
I’m not sure about the exact meaning of the various fields in get_system_info, probably some of them include only physical memory and others include also physical memory. There are also pages used by the block cache and file cache (cached_pages and block_cache_pages), which may be freed if an application needs them, but that will slow down disk operations since all the cache content has to be flushed to disk (if modified) and when there is no cache available, all data will be pushed to disk almost immediately, instead of staying in RAM and being flushed later.
So it can be a bit complicated to find the “right” value with all these parameters involved.
-pthread is there even if you don’t ask for it. It was added to the linker includes as a do-nothing option for compatibility with Linux ports. (Or so I’ve been told.)