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.
BarryG
Addict
Addict
Posts: 1804
Joined: Thu Apr 18, 2019 8:17 am

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

Post by BarryG »

jacdelad wrote: Tue Nov 23, 2021 3:50 pmIt's hard to tell my boss "Oh no, X deleted a file again and Tool Y does not run anymore."
Extract them to where the users can't see them, such as %APPDATA%?

My main app is one executable with all files embedded. I use CatchImage for the images and an embedded resource file for the sounds. I can give advice for those if you need it. I haven't embedded any other file types.
User avatar
Shardik
Addict
Addict
Posts: 1845
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

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

Post by Shardik »

In Windows you may include resources in your exe file. These resources are only loaded when needed. There will be only one copy of each resource in RAM.

Here is a simple example for including an icon resource in your exe file:
  • Copy the icon #PB_Compiler_Home + "\Examples\Sources\Data\CdPlayer.ico" for example to C:\Temp
  • Open Notepad and write "1 Icon C:\Temp\CdPlayer.ico" into the first line
  • Type <Enter> at the end of the first line
  • Save the file as C:\Temp\Icon.rc and close Notepad
  • Open the PureBasic IDE and copy the source code from below into a newly created tab.
  • In the menu of the IDE click onto Compiler > Compiler Options...
  • Select the tab "Resources"
  • At the bottom select the path C:\Temp\Icon.rc
  • Click onto "Add" and then onto "OK"
  • Now start the example code
After compiling your source code to an exe file you may delete C:\Temp\CdPlayer.ico because this icon is included as a resource in your exe file. Of course normally you shouldn't save the rc file in C:\Temp but in the same folder or a subfolder of your source code file.

In the file path of your rc file you have to take care that
- Hyphens are not allowed
- Each line has to be terminated with a CRLF

You may include many different resources in your rc file like AVIs, Bitmaps, cursors, menu entries, fonts and dialog fields.

Code: Select all

#WindowHeight = 76
#WindowWidth = 230

OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon contained in resource",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
ListIconGadget(0, 5, 6, #WindowWidth - 12, #WindowHeight - 12, "", 60)
SetGadgetAttribute(0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
IconHandle = LoadIcon_(GetModuleHandle_(0), @"#1")

If IconHandle
  AddGadgetItem(0, -1, "#1", IconHandle)
EndIf

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
User avatar
jacdelad
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa
Contact:

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

Post by jacdelad »

Putting the resources into appdata or something similar is not a good idea, because the program needs to be available to about 80 computers and updating would be a nightmare.

Using resources is a good idea. I forgot about it, because the datasecrion is much more comfortable.

However, my question has been answered, thanks to everyone involved.
Post Reply