Does the datasection stay in the memory for all the time while a program is running

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Does the datasection stay in the memory for all the time while a program is running

Post 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?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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).
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
Last edited by Demivec on Tue Nov 23, 2021 8:02 am, edited 1 time in total.
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

[Done] Re: Does the datasection stay in the memory for all the time while a program is running

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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. :wink:
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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Does the datasection stay in the memory for all the time while a program is running

Post by Caronte3D »

You could use somethig like: https://enigmaprotector.com/en/aboutvb.html to encapsulate all the files in one exe
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Does the datasection stay in the memory for all the time while a program is running

Post 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
Post Reply