Swap memory help

I am using gmp to to precise floating point arithmetic.

i also created a 20GB swap partition

what i want to know is how can i declare 4 mpf_t variable in swap space instead of ram and still be able to do all arithmetic functions on the mpf_t variables

I know it will be a lot slower but i care more about precision than speed
You can't. Why do you care anyway?
Swap space isn't more precise than ram.
Swap is automatically used by the operating system to store memory pages that don't fit into physical memory.
However, what you can do is to map a 20 GB file into memory and tell GMP to use a custom allocator that allocates memory from that region.
Swap space isn't more precise than ram.


i know it isnt but it can allow me to allocate more bits to use in the mpf_t variables which gives me more precision



Swap is automatically used by the operating system to store memory pages that don't fit into physical memory.
However, what you can do is to map a 20 GB file into memory and tell GMP to use a custom allocator that allocates memory from that region.


can you tell me how to that?
i under stand that i have to refrence http://gmplib.org/manual/Custom-Allocation.html#Custom-Allocation
Last edited on
Mapping a file into memory is done using mmap:
http://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html

You're right on about mp_set_memory_functions, that leaves writing the actual allocator and deallocator.
Having a simple allocation bitmap (vector<bool>) indicating whether a particular block is free (the block size should probably be >=1 MB) and performing a linear search for the first large enough free region will probably suffice in this case.
would it be okay if i use a different mapped file for each variable so that the allocator would be easier and give me more space to work with

and just to make sure
if i use the custom allocator i can still use the floating point library instead of the low-level library

also is it okay for me to use mmap2 so i can map more space

also i only need PROT_WRITE and PROT_READ, but not PROT_EXEC right?

can you also tell me which flags i would need
Last edited on
Topic archived. No new replies allowed.