Page 2 of 2

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

Posted: Wed Nov 24, 2021 10:12 pm
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.

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

Posted: Wed Nov 24, 2021 10:44 pm
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

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

Posted: Thu Nov 25, 2021 8:30 am
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.

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

Posted: Fri Dec 03, 2021 2:53 pm
by acreis
Good afternoon

I've done some research in the past about this issue. Windows resources were loaded in memory only when needed in good old Window 16 bits editions.

In Windows 32 bits everything is memory mapped and loaded upon request.

So using resources or datasection will be effectively the same in term of memory consumption.

Hope this help.