Where can I save temporary files?

I’m trying to have NetWorker create temporary files to be opened by other applications, but I’m not sure where to put them. The files are not expected to be saved permanently.

Are there any recommendations or best practices regarding temporary files from an app? Does Haiku have a way to remove temp files automatically, e.g. on shutdown?

1 Like

Yes: B_SYSTEM_TEMP_DIRECTORY.
It gets cleaned up with a reboot. B_SYSTEM_CACHE_DIRECTORY is not, so those “temporary” files there are more permanent. :slight_smile:

The best solution would be RAM disk. AFAIK Haiku offers it, but it’s not mounted and showed up onto the desktop by default.

any idea how to do it?

A ramdisk is mounted as RAMFS in B_SYSTEM_VAR_DIRECTORY. I’ve never used it, but you could explore and report back. :slight_smile:

3 Likes

This is not the right way to go about it, you should instead use the temporary dir humdinger mentioned. When using it the system can decide for itself if writing the file to disk makes sense or not. If you use a ramdisk you force the system to never write it to the disk, which means for long running processes (some people here run their system for days I’m told) you now have RAM that is always occupied and can never be used for anything else. (Unless written to swap, but that would be a pretty bad use for a RAMdisk…)

I can see /boot/system/var/shared_memory directory labeled as RAMFS.
Is it a ramdisk volume? The information window says it hasn’t size.
The icon looks nice and very familiar for me. It has a gauge bar like other volumes have.
If it’s ramdisk then would be nice to have it accesible as e.g. /ram

I suppose you could do a ln -s /var/shared_memory ./ram …
Not having much experience with that ramdisk, I suppose it’s dynamic(?). But as nephele mentioned, it’s probably a bad idea to use for really big files.

1 Like

If you need a ramdisk for a specific purpose you can also just mount one to wherever you want :slight_smile:

Thanks. It works. Now I have ram disk icon on the desktop. Unfortunately it lost its disk usage bar.

You could create your own ramdisk. I made this little script some years ago and haven’t used since. :slight_smile:

#!/bin/sh

# Create a 4 GiB ramdisk, format and mount it
ramdisk create -s 4gb
mkfs -q -t bfs /dev/disk/virtual/ram/0/raw RAMses
mountvolume RAMses

This will create “RAMses” in the root and should appear on the Desktop (or in “Disks”) with a free space bar.

2 Likes

Thanks! IIRC @BiPolar also had a setup for this (forgot the link), works nice, might even try this when working on rust sources, pointing CARGO_HOME there. :slight_smile:

1 Like

Love it.

Where to place the script?

/boot/home/config/settings/boot/launch/ ?

BTW, what size is the original Haiku’s ram disk? The Info window says “-”.

Works fine from there. :+1:

1 Like

Guys, it works and I love it :slight_smile:

1 Like