Re: Incude statement - is there such a thing?

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 02/02/05


Date: Tue, 1 Feb 2005 20:51:35 -0700


"jp" <paulm@kcbbs.gen.nz> wrote in message
news:3i7uv0ldam77k5utvi1ae3mr18g2k5lqaa@4ax.com...
> Thanks a lot, works like a dream and now my codes much smaller and i
> feel better managed.

Good, but have you noticed that you get poorer compile time messages when
doing it this way?

> Do you know the overhead on memory when using this, as i have created
> two separate files and they work well together but i am unsure as to
> if they are constantly loaded into memory or per script.

That is a good question that I know part of the answer to. If the "included"
script defines subs, functions, classes, global constants, or global
variables, those items remain compiled into existence in memory until the
main script completes. The only way I know to reduce the memory requirement
of, for example, a very large function called BIG would be to include a file
that defines a much smaller version. I do not know for a fact, though, how
effectively this releases the memory dedicated to the old version.

I suspect that the same would hold true for any and all code included this
way, even if it were straight, inline, script level code. If, for example,
you had 50 statements that you wanted to execute 1000 times in a loop. If
you have that include call in the loop, it might be that 999 new instances
of this code would co-exist in memory, each having been executed only once,
and not being capable of being re-used. If that were the case, you would be
much better off to embed the 50 lines of code directly in the loop.

> I have 15 scripts with the references in that you mention and wonder
> if this is an over kill.

I think it might be. Reminds me a bit of a time long ago when I used to
tweak the assembler code output from a Fortran compiler to make it a bit
tighter and faster. IIWY, I would construct my code in the most
straightforward manner so that I was not writing code to manage code, and
not try to solve performance issues until they actually happen.

Alternately, have you considered using WSH's .WSF format? This allows you to
statically include source files, and even mix WSH-enabled languages.

/Al

> jp
>
> On Sun, 30 Jan 2005 20:51:56 -0500, "B-Mann" <b__mann@hotmail.com>
> wrote:
>
> >I use the following in my .vbs files to include a common file that
contains
> >global variables, constants, and useful functions:
> >
> >ExecuteGlobal
>
>CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Scripts\Common.
inc").ReadAll
> >
> >(The above should be on a single line)
> >
> >B-Mann
> >
> >"jp" <paulm@kcbbs.gen.nz> wrote in message
> >news:rj2rv0dh67de837jbaqfajl4g317o3op37@4ax.com...
> >>
> >> Currently the scripts i have are not ASP/Web orientated, just basic
> >> scripts to deploy fixes and enchantments.
> >>
> >> The idea would be great to have something like a Constants,vbs/txt
> >> file that i could modify as required and not have to do the same to
> >> all my scripts, so this type of feature feels good if i can understand
> >> how to implement it without getting bogged down with rewriting my
> >> scripts. Unless that's the only way.
> >>
> >>
> >> jp
> >>
> >> On Fri, 28 Jan 2005 13:40:45 -0600, "McKirahan" <News@McKirahan.com>
> >> wrote:
> >>
> >>>"jp" <paulm@kcbbs.gen.nz> wrote in message
> >>>news:fm3lv09l4dmb2q3d7330ps33ndsbjc9vpd@4ax.com...
> >>>> I found the following reference on the internet at AVID's web site
and
> >>>> since i had never heard of the Include statement before i wondered if
> >>>> anyone else has and if this is now obsolete as the page was dated
> >>>> 2002. Can't believe that this feature would be removed in such a
short
> >>>> space of time 2002-2004/5.
> >>>>
> >>>> Using this method would really help me with my code, already using a
> >>>> similar process via Function calls however pulling from another file
> >>>> seems more practical to me, though those of you who are more
> >>>> conversant with VBS may be able to provide better direction on this.
> >>>>
> >>>> Also looking at the 5.6 CHM there is no reference to the include
> >>>> statement that i have found so far.
> >>>>
> >>>> -----snip it
> >>>>
> >>>> Including External Scripts (Windows Only)
> >>>> You can include an external script file (.vbs or .js) in another
> >>>> script file. This lets you reuse common routines without the need to
> >>>> paste them into every file. Once you have included a script file as
> >>>> shown below, the routines exist in the global namespace and you can
> >>>> call them in the same way you would call any other routine in the
> >>>> script.
> >>>>
> >>>>
> >>>> These techniques work only on Windows platforms. This is because the
> >>>> Scripting.FileSystemObject is not available on IRIX or Linux.
> >>>>
> >>>>
> >>>>
> >>>> Including External Files Using VBScript
> >>>> Here's an example of including external .vbs files using VBScript:
> >>>>
> >>>>
> >>>> '-------------------------------------------------------
> >>>> '-- Include procedure, works only on Windows
> >>>> '-----------------------------------------------------------
> >>>>
> >>>> Sub Include( cNameScript )
> >>>> Set oFS = CreateObject("Scripting.Filesystemobject")
> >>>> Set oFile = oFS.OpenTextFile( cNameScript )
> >>>> ExecuteGlobal oFile.ReadAll()
> >>>> oFile.Close
> >>>> End Sub
> >>>>
> >>>> '-- Samples
> >>>> Include "C:\user\username\Softimage\Scripts\globals.vbs"
> >>>> Include "C:\user\username\\Softimage\Scripts\utils.vbs"
> >>>>
> >>>>
> >>>>
> >>>> jp
> >>>
> >>>Where are you looking to use this?
> >>>
> >>>
> >>>If inside a Web page, try:
> >>>
> >>><script type="text/javascript" src="your_include_file.js"></script>
> >>>
> >>>or if you want to do it in VBScript for IE only browsers:
> >>>
> >>><script type="text/vbscript" src="your_include_file.vbs"></script>
> >>>
> >>>
> >>>The extension doesn't matter; ".inc" is often used.
> >>>
> >>>
> >>>If it's for an ASP page, try:
> >>>
> >>><!--#include file="your_include_file.asp"-->
> >>>
> >>>
> >>>You could also look into WSF.
> >>>
> >>
> >
>



Relevant Pages

  • Re: environment variable
    ... Each site would have script that they would run to get the addresses for ... I have a "FOR" loop runing. ... doing a call to set the variable in volitle memory and using that variable ... >> The problem experiencing is I can not seem to do the same in vbscript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Possible memory leak using $sth->{NAME} ?
    ... > routine seems to leak 1 SV per execution. ... > to be a fairly insignificant amount of memory. ... > of memory per trip through the loop. ... > version of the script where the loop executes once, ...
    (perl.dbi.users)
  • Re: Incude statement - is there such a thing?
    ... I can't imagine any memory usage issues. ... And it that WSF references ... other script files (as the Docs often suggest to be ... > you had 50 statements that you wanted to execute 1000 times in a loop. ...
    (microsoft.public.scripting.vbscript)
  • Re: PHP memory garbage collection
    ... If I use a very large XML file then the PHP crashes inside the loop (Fatal error: Allowed memory size of 10485760 bytes exhausted) - indicating that the problem lies within loop somewhere. ... If PHP uses all the memory until the end of the script ...
    (comp.lang.php)
  • Re: Is there memory leak in mex programming?
    ... Does anyone ever compile m code into a c++ shared library? ... and at the end matlab runs out of memory. ... it only loop 1x. ...
    (comp.soft-sys.matlab)

Quantcast