Amiga.org
Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: lurkist on March 03, 2007, 07:17:17 PM
-
What does that switch do?
Cheers
-
There is no PURE in assigns.
You probably mean PURE/S in resident command. This "forces" the command to be considered pure, even if the 'P' protection bit is not set.
-
So, what is the "PURE" flag actually used for? I know that some commands complain they cant be made resident in the shell unless you use this.
Does that mean they arent really supposed to be made resident?
-
Do not ever use PURE unless you know for a fact that the command really is pure.
Using the PURE option on impure commands will lead to disasterous results.
-
So what qualifies a pure or impure command? Is it something about the way they were written?
-
@mel_zoomy
Yes they must be written and/or assembled and/or compiled a certain way.
Since you are coding C... which compiler are you using?
Technically a pure program must place ALL global variables in allocated memory or on the stack. For example local variables go on the stack in C so they are 100% pure. But normal variables just go into regular memory and that is impure. But if you do an AllocMem() and store the vars in that memory then that is pure.
PURE means that the code can be executed multiple times simultaneously.
-
Slight correction there: You don't need to AllocMem your variables for the program to be pure. You can also use stack (local variables). Pure apps can't use globals/static data.
-
Piru wrote:
You probably mean PURE/S in resident command.
Sorry, yes that's exactly what I meant.
@thread - oops, I've tried all sorts of other apps as resident using the PURE switch, so far all the continents of Earth are still in place (last time I checked at least).
So give us some examples of programs which are PURE. (And some which are definitely IMPURE!)
-
Piru:
"Pure apps can't use globals/static data."
I thought all C string literals were basically static though? If that is true does it mean you can use global and static data provided it is constant?
-
In C you don't need to AllocMem() any vars or use the stack to create a pure exe. You just need to compile and link with the proper pure options and the compiler takes care of everything for you.
-
@lurkist
Just run 1 of those apps twice at the same time and the contents of the entire Amiga universe running on your machine will be displaced in a firey cataclysmic crash. Well it was nice to have known you. Please write your will and leave all your Amigas to me before you try it. Thanx. :-D
-
@mel
Yes you can use constants any way you want and still be pure.
That is why I said "variables". You are only limited regarding data which is writeable.
-
Yeah static const is ok.
Anyway, as pointed out some compilers can do the magic for you even if you use globals. But in that case the compiler will have some magic code there in startup that allocates and duplicates any static data for each instance of the application.
Today - with fast HDDs - creating pure apps isn't really required.
-
Piru wrote:
Yeah static const is ok.
To be more precise, any const data, be it static or not, is ok, as long as it's not put in the BSS section.
Today - with fast HDDs - creating pure apps isn't really required.
Pure executables are also about saving memory, as you don't have to load the TEXT part of the program more than once in memory, much like libraries.
Indeed, libraries are pure executables by force.
-
To be more precise, any const data, be it static or not, is ok, as long as it's not put in the BSS section.
Well naturally. That "static const" was about the specific case when static is ok.
Pure executables are also about saving memory, as you don't have to load the TEXT part of the program more than once in memory, much like libraries.
True. However, residents also waste memory. If the particular program is not running, it still sits in the memory eating chunk of memory for nothing.
In fact, not many programs really run simultanously often enough to justify being resident in memory.
The most benefit from resident commands comes with slow media (floppies, cd-rom etc).
-
I thought the point of having something resident was not if it was run simutaneously, but if it was run multiple times to prevent multiple accesses of the same sector on hard drives (or floppies). For instance, copying a large amount of files. Sure you could use a multi-select option or something, but if you're not the disk is accessing the "copy" file each time, thus wearing it out.
That and the speed increase of course.
Or have I misunderstood the purpose of Resident?
-
The reason resident is used in startup-sequence is to speed up the booting (esp with floppies).
Not accessing the disk is the result, but the motivation wasn't reducing disk access to avoid media wearing. Naturally this might have been someone else's motivation for using residents...
-
It also means the code is able to be resident because it is RE-ENTRANT. Meaning you call call it multiple times using the same memory allocation etc.. (well not exactly but that's the general IDEA)..