473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Yet another global vars question

Lee

I've been programming with Delphi for the past 4 years or so and while
Delphi does allow globals, I use them very judiciously. I say that I
*do* use them because I think that in some cases they are a good choice.

Now in C# there are no global vars. MSDN and google say that I can use
static classes (err, or static methods in classes) like Type.TypeOf,
etc.

What if I have an object that contains resources for the rest of my
application such as a pre-opened database connection or maybe static
data that makes sense to keep in memory because it's used so often. Is
overriding the constructor of every object in the application the only
(best? Advised?) way of sharing an object accross the application?

Thanks for any clarity..

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
Mar 4 '06 #1
2 1322
Lee <lu************ *@yahoo.com> wrote:
I've been programming with Delphi for the past 4 years or so and while
Delphi does allow globals, I use them very judiciously. I say that I
*do* use them because I think that in some cases they are a good choice.

Now in C# there are no global vars. MSDN and google say that I can use
static classes (err, or static methods in classes) like Type.TypeOf,
etc.

What if I have an object that contains resources for the rest of my
application such as a pre-opened database connection or maybe static
data that makes sense to keep in memory because it's used so often. Is
overriding the constructor of every object in the application the only
(best? Advised?) way of sharing an object accross the application?


No, in those cases you can use public static members - preferrably
either constants or properties which can return the data (possibly
having lazily loaded them, etc).

For database connections, however, you should usually just let the
built-in connection pooling do the job for you - open the connection
and close it as early as possible, and the connection pool will keep
the *actual* connection open for you.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 4 '06 #2
Hello lee,

For your reason pooling and cache is solutions.
Connections generally keeps in pool.
If u want some object to be in memmory - keep them in cache.
Sharing object accross application depends on this app. it's either on singleton/monostate
object, or horisonted scaled object

l> I've been programming with Delphi for the past 4 years or so and
l> while Delphi does allow globals, I use them very judiciously. I say
l> that I *do* use them because I think that in some cases they are a
l> good choice.
l>
l> Now in C# there are no global vars. MSDN and google say that I can
l> use static classes (err, or static methods in classes) like
l> Type.TypeOf, etc.
l>
l> What if I have an object that contains resources for the rest of my
l> application such as a pre-opened database connection or maybe static
l> data that makes sense to keep in memory because it's used so often.
l> Is overriding the constructor of every object in the application the
l> only (best? Advised?) way of sharing an object accross the
l> application?
l>
l> Thanks for any clarity..
l>
l> "Upon further investigation it appears that your software is missing
l> just one thing. It definitely needs more cow bell..."
l>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3333
by: lkrubner | last post by:
If I set a variable at the top of my code like this: $name = "Lawrence"; It is now a global variable. If, later on, in a function, I want to do this: function uppercaseName() { global $name;
3
11904
by: Sean Berry | last post by:
How do I rectify this? ------vars.py------ #!/usr/local/bin/python def setUserid(value): userid = value def getUserid():
13
1645
by: David Rysdam | last post by:
Getting no answer yesterday, I've done some investigation and I obviously don't understand how python namespaces work. Here's a test program: #!/usr/bin/python b = 2 def sumWithGlobal(a): return a + b
6
2026
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following code: #def put_file(file_id, delete=False): # """ Function to put the file on the FTP Server # """ # print " FTP for this file started"
16
2286
by: WaterBug | last post by:
When clicking on the following link from an email i.e - http://myserver/myapplication/myprogram.asp?urlvar1=some%20stuff&urlvar2=more%20stuff I get a server 500 error. With that same browser window open, if I click the link from the email again I get the desired page. The results are the same if the url is copied and pasted into the brower but the 'go' must be pressed twice. It appears that the server is trying to resolve the url vars...
10
2642
by: Kleenex | last post by:
Reason: I am working on an embedded project which has very limited memory (under 512 bytes, 60 or so of which is stack space), which translates into limited stack space. In order to save on stack space, I tried to only use parameters and stack space for things which are truely temporary. Instead of passing a pointer to a data structure which should always be populated with data, I have the data structure declared as a global variable and...
9
8656
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
1
1291
by: Konstantinos Pachopoulos | last post by:
Hi, i had posted earlier for not being able to declare global vars. No i followed the suggestions and created a class, but still the vars do not seem to have a global scope. I have tried pretty much everything. Any advice appreciated... Here: ======================================================== #!/usr/bin/env jython #imports
4
1756
by: pcaisse | last post by:
I'm having issues sharing global variables with Explorer. This problem probably has a simple answer (as with most newbie questions). The script.pl file: #!/usr/bin/perl -w use strict; use diagnostics; use sigtrap;
0
1442
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no* program wide globals. There are only module wide globals. Also, the "global isglobal" is absolutely meaningless as anything declared there is a (module level) global by definition.
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.