Page 1 of 2
Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 6:30 pm
by jacdelad
Hi,
I hope I find the right words: When working with a datasection I can access stored values (like a long or something) the same way I would access it within a memorysection allocated with AllocateMemory(). Does this mean all the stuff from the datasection is in my RAM while my program is running? If so, can I free this memory (and of course lose access) or is this counterproductive?
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 6:52 pm
by Tenaja
It is persistent, and does not go away. I have never tried, but doubt you can free it. that would be modifying an executable, and most operating systems frown upon that.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 9:11 pm
by jacdelad
Nonono, I don't mean altering the executable. I don't want do lose my resources. I just mean whether it's always loaded into the ram or when it's needed. I can use the addresses, like ?MyAdress, like normal addresses, so I assume it's always in the ram, whenever my program runs. This means that I maybe use some ram for things I don't need, like an embedded picture, that is loaded via CatchImage(#PB_Any,?MyAddress), but I can't remove the memory where the picture is loaded from. Do you understand what I mean? this sounds like a waste of ram on longterm sight (if I use a big datasection instead of standalone files).
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 9:57 pm
by idle
Yes it stays in memory but you can also write to a datasection while the exe is running which can be useful if you want to dynamically change parameters or state while the program runs.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 10:15 pm
by juergenkulow
Code: Select all
; Datasection Section
*ptr.Byte=?Start
*ptr\b=49
; ! pb_data[0]=48;
Read.b i
Read.b j
Read.s s.s
SetClipboardText(Str(i)+" "+Str(j)+" "+s)
DataSection
Start:
Data.b 47,11
Data.s "Hello Universe"
EndDataSection
; C Backend:
; unsigned char pb_data[] = {47,11
; ,0x48,0x0,0x65,0x0,0x6C,0x0,0x6C,0x0,0x6F,0x0,0x20,0x0,0x55,0x0,0x6E,0x0,0x69,0x0,0x76,0x0,0x65,0x0,0x72,0x0,0x73,0x0,0x65,0x0,0,0
; };
; ASM Backend
; section '.data' Data readable writeable
; l_start:
; PB_DataSectionStart:
; db 47,11
; dw 72,101,108,108,111,32,85,110,105,118,101,114,115,101,0
; SYS_EndDataSection:
; x64dbg
; Adresse=000000013FF05000
; Größe=0000000000001000
; Name=".data"
; Inhalt der Auswahl=Initialisierte Daten
; Typ=IMG
; Aktueller Zugriff=-RW--
; Zugriff (beim Erstellen)=ERWC-
; 49 11 Hello Universe
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Mon Nov 22, 2021 11:48 pm
by jacdelad
Well ok, thanks for the answers, I think I understand now.
So, I think it would be a good thing to be able to flush the data/free it. Like, if I have a lot of pictures in my code, load them and the I don't need the entire datasecrion anymore. Is this something for the wishlist or not? I don't like wasting resources.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 12:31 am
by NicTheQuick
On the one hand the data within the datasection is accessible inside your application as it would be a normal memory section. But usually it will not compromise all your RAM if the datasection is huge. At first it will be file mapped (virtual memory) and only loaded into you physical memory when it gets accessed. And I would assume that your operating system will swap it to virtual memory again if you do not access it over a longer period and other processes need RAM.
Source:
https://stackoverflow.com/questions/279 ... nto-memory
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 3:55 am
by Demivec
jacdelad wrote: Mon Nov 22, 2021 11:48 pmSo, I think it would be a good thing to be able to flush the data/free it. Like, if I have a lot of pictures in my code, load them and the I don't need the entire datasecrion anymore. Is this something for the wishlist or not? I don't like wasting resources.
It doesn't make sense as a wishlist request. You already have the choice of either putting something in a DataSection to be in memory while your program runs (and duplicated if you 'catch' them) or you load and free then as needed.
[Done] Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 6:17 am
by juergenkulow
Code: Select all
; DLLImage
ProcedureDLL.i startdata()
ProcedureReturn ?start
EndProcedure
DataSection
Start:
IncludeBinary "PureBasic.bmp" ; Please adapt.
EndDataSection
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_DLL
CompilerError "Please use Compiler Option Executable Format DLL and Compiler Executable generate."
CompilerEndIf
Code: Select all
; catchImageDLL
If OpenLibrary(0, "dllImage.dll")
CatchImage(0,CallFunction(0,"startdata"))
CloseLibrary(0) ; And free memory from dllImage.dll.
OpenWindow(0, 0, 0, 245, 105, "CatchImageDLL", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 100, 83, ImageID(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
MessageRequester("Error","Can not find dllImage.dll.")
EndIf
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 9:47 am
by jacdelad
That makes sense, but if I want to make a program that only consists of one file I feel a bit limited. I don't like putting resources into the folder so everyone can manipulate them. Stupid users deleting something and it's not working anymore. One file, that's all. Maybe I have to rethink my concept or live with it.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 12:21 pm
by NicTheQuick
jacdelad wrote: Tue Nov 23, 2021 9:47 am
That makes sense, but if I want to make a program that only consists of one file I feel a bit limited. I don't like putting resources into the folder so everyone can manipulate them. Stupid users deleting something and it's not working anymore. One file, that's all. Maybe I have to rethink my concept or live with it.
If users do that then it's their fault, not yours.

Also if you install your software properly inside the "Program Files" directory on Windows or in /usr/local/bin on Linux and libraries and shares in /var/lib and /usr/share then there should be no problem unless the user decides to become root.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Tue Nov 23, 2021 3:50 pm
by jacdelad
It's hard to tell my boss "Oh no, X deleted a file again and Tool Y does not run anymore.". That's why I decided to put it all in one file.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Wed Nov 24, 2021 10:34 am
by Caronte3D
You could use somethig like:
https://enigmaprotector.com/en/aboutvb.html to encapsulate all the files in one exe
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Wed Nov 24, 2021 10:43 am
by jacdelad
Thanks for the idea, but I think that would an overkill. Beside that I have to purchase it, my problem is just about a few MBs of ram and also nothing to hide.
Re: Does the datasection stay in the memory for all the time while a program is running
Posted: Wed Nov 24, 2021 9:33 pm
by idle
ezpack, compresses files to a pack which you can then catch from memory without writing them to disk
viewtopic.php?f=27&t=52586