/CREATERESIDENT

Just starting out? Need help? Post your questions and find answers here.
User avatar
useful
Enthusiast
Enthusiast
Posts: 402
Joined: Fri Jul 19, 2013 7:36 am

/CREATERESIDENT

Post by useful »

https://www.purebasic.com/documentation ... dents.html

Residents are precompiled files which are loaded when the compiler starts. They can be found in the 'residents' folder of the PureBasic installation path. A resident file must have the extension '.res' and can contain the following items: structures, interfaces, prototypes, macros and constants. It can not contain dynamic code or procedures.

When a resident is loaded, all its content is available for the program being compiled. That's why all built-in constants like #PB_Event_CloseWindow are available, they are in the 'PureBasic.res' file. All the API structures and constants are also in a resident file. Using residents is a good way to store the common macros, structure and constants so they will be available for every programs. When distributing an user library, it's also a nice solution to provide the needed constants and structures, as PureBasic does.

To create a new resident, the command-line compiler needs to be used, as there is no option to do it from the IDE. It is often needed to use /IGNORERESIDENT and /CREATERESIDENT at the same time to avoid duplicate errors, as the previous version of the resident is loaded before creating the new one.

Residents greatly help to have a faster compilation and compiler start, as all the information is stored in binary format. It is much faster to load than parsing an include file at every compilation.


Everything is described simply and logically, but

pbcompiler -h 
or
pbcompilerc -h

/CREATERESIDENT: Unknown switch

Can someone give an example of creating and using a custom res file?
Last edited by useful on Sat Oct 12, 2024 6:16 am, edited 1 time in total.
Dawn will come inevitably.
User avatar
useful
Enthusiast
Enthusiast
Posts: 402
Joined: Fri Jul 19, 2013 7:36 am

Re: /CREATERESIDENT

Post by useful »

I answer myself.

For example 

OnOff.pb

Code: Select all

#ON=1
#OFF=0
t. e. error in the documentation and the key /IGNORERESIDENT REQUIRED!

... pbcompiler OnOff.pb /IGNORERESIDENT OnOff.res /RESIDENT OnOff.res /QUIET
Last edited by useful on Sat Oct 12, 2024 6:17 am, edited 1 time in total.
Dawn will come inevitably.
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: /CREATERESIDENT

Post by BarryG »

From my batch file in my PureBasic folder:

Code: Select all

del "Residents\[MyResidents].res"
"Compilers\pbcompiler.exe" MyResidents.pb /resident [MyResidents].res
move [MyResidents].res "Residents\"
pause
The file "MyResidents.pb" holds my definitions.
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: /CREATERESIDENT

Post by Denis »

A+
Denis
User avatar
useful
Enthusiast
Enthusiast
Posts: 402
Joined: Fri Jul 19, 2013 7:36 am

Re: /CREATERESIDENT

Post by useful »

I have already found out everything for myself and pointed out above that there is an error in the documentation. Well, or the documentation is correct (as intended), but not implemented correctly. :D
Dawn will come inevitably.
Post Reply