Is a project already loaded...

Started by mr nick, April 30, 2009, 02:21:45 AM

Previous topic - Next topic

mr nick

Is there any way of determining if a project is already loaded - or more particularly if it is unloaded? In one of my routines I have a multiple dialogs all built into the same project and in most circumstances they are all pretty much standalone items that are loaded and unloaded on an 'as-needed' basis but due to a particular set of circumstances in the cause/effect of some aspects of my routine there are rare instances where a routine can be called from inside another but both routines have an 'unload' call in them. As a result, when the first unload call is passed, all is well and good but then the second unload goes out and I get an error message because the project has been previously unloaded. So what I need to try and determine is whether there is actually anything to unload or not - or possibly a similar outcome as happens when you load a project that is already loaded - i.e. nothing happens and no error message is issued.

Kerry


You could try something like this ..
Code (autolisp) Select


(if (not (= (type StuffIsLoaded) 'str))
    (setq StuffIsLoaded (dcl_project_load "KDUB_SteelSections"))
    ;; else
    ;; it's already loaded
)

(if (= (type StuffIsLoaded) 'str)
    (progn (dcl_project_unload "KDUB_SteelSections")
           (setq StuffIsLoaded nil)
    )
)

Perfection is not optional.
My other home is TheSwamp

mr nick

Thanks Kerry - a better approach than the one I was considering of reloading the project directly before the unload call.

Fred Tomke

So why don't you use GetProjects method?

Code (autolisp) Select
(if (member "KDUB_SteelSections" (dcl_GetProjects)) (dcl_project_unload "KDUB_SteelSections"))

or

Code (autolisp) Select
(if (not (member "KDUB_SteelSections" (dcl_GetProjects))) (dcl_project_load "KDUB_SteelSections")))

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

mr nick

Quote from: Fred Tomke on April 30, 2009, 04:27:39 AM
So why don't you use GetProjects method?

Because I didn't know it existed. But now I do  ;D

Thanks Fred.

owenwengerd

Why do you need to unload the project in the first place?

mr nick

Quote from: owenwengerd on April 30, 2009, 05:39:36 AM
Why do you need to unload the project in the first place?

To quote from the help file...
This method unloads a project, freeing its memory.

If there is no need to unload a project, why would such an option exist?

owenwengerd

There are cases where a project needs to be unloaded, but they are unusual and rare. What is your reason?

mr nick

If it's possible to free up some memory, however much or little, then that's a good thing in my book - every little helps.

Kerry


In the cold light of day ...
Nick;
You dont need to check prior to loading
(dcl_project_load   .... This function does nothing if the project is already loaded, unless the optional ForceReload argument is T

and Fred; yes ! Using the dcl_getProjects Method would be better. :)
Perfection is not optional.
My other home is TheSwamp

owenwengerd

Quote from: mr nick on April 30, 2009, 06:40:41 AM
If it's possible to free up some memory, however much or little, then that's a good thing in my book - every little helps.

Freeing up physical memory is always good, but the OS can do a good job of that by paging inactive physical memory to disk. I'd guess that in the vast majority of cases you will see zero performance impact by leaving a project loaded. It takes time to unload a project, so unloading a project means you're paying an immediate performace penalty for negligible future gains.

Fred Tomke

Hm, how much memory does a loaded project need?
Ok, memory will be needed when a project will be loaded. But much more memory will be addressed, when a form will be shown and will be freed up when the form will be closed again. So the needed memory of the simply loaded project should be very minimal.

That's the way I explain it myself, but this may be completely wrong. So please correct me.

When I was on ObjectDCL I had one single odc-file for all forms. Loading the project took a recognizable time. But now when I convert all these projects to OpenDCL I devide them into several projects (for layers, blocks, certain managers, migration, and so on). So in this case some projects are not loaded if not commands are called which uses forms from these projects. That also helps decreasing the use of memory.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

A loaded project will generally consume memory equal to roughly 3 to 4 times the project file size. As you point out, loading and (to a smaller extent) unloading projects can take a noticeable amount of time, whereas an unused project will have its physical memory paged to disk, thus resulting in zero physical memory consumed.