Memory access ? (Solved on 64 bit distro)
Memory access ? (Solved on 64 bit distro)
Hi,
just more work with RAM + bigger arrays, unclear thing founded.
Which kind of computer memory is Freebasic able to use ?
I see only "mem" and "xyAllocate" keywords and disproportion between memory stats.
Htop says :
Total 2.2 Giga
Used 680 Mega
Buffers 36 Mega
Cached 1.5 Giga
FB mem after program start says:
170 Mega free
When building big array (cca 600 Mega planned size), program freezes after touching 900 Mega Used memory, by Htop.
It looks like Cached part of memory, 1,5 Giga , is hidden/unaccessible for FB .
Can I access it in some manner ?
[
just more work with RAM + bigger arrays, unclear thing founded.
Which kind of computer memory is Freebasic able to use ?
I see only "mem" and "xyAllocate" keywords and disproportion between memory stats.
Htop says :
Total 2.2 Giga
Used 680 Mega
Buffers 36 Mega
Cached 1.5 Giga
FB mem after program start says:
170 Mega free
When building big array (cca 600 Mega planned size), program freezes after touching 900 Mega Used memory, by Htop.
It looks like Cached part of memory, 1,5 Giga , is hidden/unaccessible for FB .
Can I access it in some manner ?
[
Last edited by ppf on May 29, 2019 0:09, edited 1 time in total.
Re: Memory access ?
try using redim instead of dim
Re: Memory access ?
On my (linux) laptop with 8 GB memory, this code runs fine:
Output:
The only odd thing is that fre() still returns the same value after memory allocation.
Code: Select all
const as longint KB = 1024
const as longint MB = KB * 1024
const as longint GB = MB * 1024
const as longint BLOCK_SIZE = 4 * GB
Print "Free memory: "; fre() \ MB; " megabytes"
print
print "allocating bytes"
dim as ubyte ptr pBlock = allocate(BLOCK_SIZE)
if pBlock = 0 then print "Error allocate" : end -1
print
Print "Free memory: "; fre() \ MB; " megabytes"
print
print "filling bytes ..."
for i as longint = 0 to BLOCK_SIZE-1
pBlock[i] = (i and 255)
next
print
Print "Free memory: "; fre() \ MB; " megabytes"
print
print "checking bytes ..."
for i as longint = 0 to BLOCK_SIZE-1
if pBlock[i] <> (i and 255) then print i; "Byte error": exit for
next
print
Print "Free memory: "; fre() \ MB; " megabytes"
print
print "freeing bytes"
deallocate pBlock
print
Print "Free memory: "; fre() \ MB; " megabytes"
print
Code: Select all
Free memory: 3732 megabytes
allocating bytes
Free memory: 3732 megabytes
filling bytes ...
Free memory: 141 megabytes
checking bytes ...
Free memory: 142 megabytes
freeing bytes
Free memory: 4245 megabytes
Re: Memory access ?
'Fre' returns the memory size allocated by the OS at the call time. This size is dynamically readjusted by the OS during program execution.
For fbc 32-bit, maximum allocated memory size < 2 GB.
For fbc 64-bit, maximum allocated memory size < virtual memory.
For fbc 32-bit, maximum allocated memory size < 2 GB.
For fbc 64-bit, maximum allocated memory size < virtual memory.
Re: Memory access ?
Thanks for your replies and code, very helpful!
But my distro seems preconfigured strangely.
I was able to allocate memory for array in amount of 256 Mega only; after additional web search
founded two commands
"sysctl -w vm.drop_caches=3"
"sysctl vm.swappiness=2"
Also added ramdisk of 512 Mega.
After that examinating I finally got to allocate of 512 Mega, but allocate test prog is on edge of hanging.
'Htop' shows both CPU cores on 99%.
'Mem' shows Cached memory downed to 1 Giga only.
This is useless for my real prog.
Switching to 64 bit distro.I want to see my 8Giga RAM completely accessible, in work.
But my distro seems preconfigured strangely.
I was able to allocate memory for array in amount of 256 Mega only; after additional web search
founded two commands
"sysctl -w vm.drop_caches=3"
"sysctl vm.swappiness=2"
Also added ramdisk of 512 Mega.
After that examinating I finally got to allocate of 512 Mega, but allocate test prog is on edge of hanging.
'Htop' shows both CPU cores on 99%.
'Mem' shows Cached memory downed to 1 Giga only.
This is useless for my real prog.
Switching to 64 bit distro.I want to see my 8Giga RAM completely accessible, in work.
Re: Memory access ?
Well, currently on 64 bit distro.
'free' says 5.7 Giga RAM available. OK.
But compiled prog doesn't work.
Where are FAQ , hints, other dcs etc related to 64 bit Freebasic compiling ?
Ldd says missing libraries, but all is installed in 64 bit version.
Seems like 64 bit fbc tries to compile source as 32 bit default target, I don't understand, what is wrong.
Could somebody navigate me to the light in the darkness ?
'free' says 5.7 Giga RAM available. OK.
But compiled prog doesn't work.
Where are FAQ , hints, other dcs etc related to 64 bit Freebasic compiling ?
Ldd says missing libraries, but all is installed in 64 bit version.
Seems like 64 bit fbc tries to compile source as 32 bit default target, I don't understand, what is wrong.
Could somebody navigate me to the light in the darkness ?
Re: Memory access ?
You probably meed to download the 64 bit libraries (NOT included, just the .bi files).ppf wrote:Ldd says missing libraries, but all is installed in 64 bit version.
See: External Libraries Index
No, its only "running" on 64 bit HW/OS and "producing" 64 bit binaries.ppf wrote:Seems like 64 bit fbc tries to compile source as 32 bit default target, I don't understand, what is wrong.
Re: Memory access ?
Ahh, you are right ! Completely forgot on additional libs of 3rd party.
Used 'libpng' for beauty intro image, sGui for Messagebox and C function 'fflush'.
Firstly it 'll be commented out, to see what happened next.
Much appreciated advices, thank you again.
Used 'libpng' for beauty intro image, sGui for Messagebox and C function 'fflush'.
Firstly it 'll be commented out, to see what happened next.
Much appreciated advices, thank you again.
Re: Memory access ?
For the 'default' stuff that FBC needs, see: https://www.freebasic.net/wiki/wikka.ph ... Installing
Re: Memory access ?
Yes, founded&compared with yum.Thank you.
Now, uff, it works.Seeing on ldd output, it searches libs in /lib/ folder.
So added 32 bit version libX randr render pm.., compiled and works in quick test.
Sorts seems a bit slower, then on old 32 bit distro.No changes in sources.
IMO I have 32 bit app compiled on 64 bit distro, by default.
But why ?
Now is time to check accessible memory, big arrays&files read/write and speed.
Forwarding ;
Now, uff, it works.Seeing on ldd output, it searches libs in /lib/ folder.
So added 32 bit version libX randr render pm.., compiled and works in quick test.
Sorts seems a bit slower, then on old 32 bit distro.No changes in sources.
IMO I have 32 bit app compiled on 64 bit distro, by default.
But why ?
Now is time to check accessible memory, big arrays&files read/write and speed.
Forwarding ;
Re: Memory access ?
Are you sure you installed 64-bit FBC?ppf wrote:IMO I have 32 bit app compiled on 64 bit distro, by default. But why ?
I have both installed (for testing). Renamed them after installing to fbc32 & fbc64:
badidea@laptop:~$ fbc32 --version
FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for linux-x86 (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
badidea@laptop:~$ fbc64 --version
FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for linux-x86_64 (64bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
I see have to update to the latest version I see.
Re: Memory access ?
Yes, I have fbc 64 bit installed.
After searchin, founded this compiler parameter - 'fbc -arch 64...'.
Then correctly identified bad 32 bit libs and code in compiled sources.
After correction, compiled Ok.Now Ldd shows searchin in /lib64/ as awaited.
Memory is Ok too.
Looks good !
After searchin, founded this compiler parameter - 'fbc -arch 64...'.
Then correctly identified bad 32 bit libs and code in compiled sources.
After correction, compiled Ok.Now Ldd shows searchin in /lib64/ as awaited.
Memory is Ok too.
Looks good !