473,750 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

initialize a complex constant in a class

Hi,

I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?

thanks!
ibiza

Feb 22 '06 #1
10 1564


Add a shared variable to hold the dictionary and populate it in the
class Initializer

e.g.

public class Something

private shared _dict as HashTable

shared sub new()

_dict = new ArrayList
' Add the items to the HashTable
end sub

end class

hth,
Alan.

Feb 22 '06 #2
You could expose this as a shared member initialized in the shared
constructor ?

Patrice

--

"ibiza" <la******@gmail .com> a écrit dans le message de
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Hi,

I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?

thanks!
ibiza

Feb 22 '06 #3
thanks! :)

I guess you both said the same thing?

Feb 22 '06 #4
is there a collection class that acts as a bidirectional dictionary?

I mean that if I add the entry (1, 42) in a dictionary, and I then do
dic(1), it will return 42.
but is there a class would return the same, but moreover if I do
dic(42), would return 1?

thanks! :)

Feb 22 '06 #5

Why not use an ArrayList and implement BinarySearch?

ibiza wrote:
is there a collection class that acts as a bidirectional dictionary?

I mean that if I add the entry (1, 42) in a dictionary, and I then do
dic(1), it will return 42.
but is there a class would return the same, but moreover if I do
dic(42), would return 1?

thanks! :)

Feb 22 '06 #6
"ibiza" <la******@gmail .com> schrieb:
I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?


\\\
Private Shared m_Bla As Dictionary = New Dictionary(...)

Private Shared ReadOnly Property Bla() As Dictionary
Get
Return m_Bla
End Get
End Property
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 22 '06 #7
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #8
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #9

use .IndexOf() for that

ibiza wrote:
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #10

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

Similar topics

13
14840
by: Kyle | last post by:
Hi, Is it possible to initialize a constant memeber array in a class? I tried several syntax but all failed. class A { public: A(); ~A(); private:
5
4572
by: Jim Langston | last post by:
What I want to do: have a vector of ints in my class initialized with 0 to 499 which will later be pushed/popped out of the vector by instances. What I have: class CParticleStream // Yes, I know you wouldn't use 'C' { private: static std::vector<int> PSArray; public:
3
2124
by: dpriver | last post by:
I have to initialize a huge constant array of structures(60000~100000), used as a lookup table , but it failed with System.InvalidProgramException when the items reach 18400. and if I change the item type from struct to class, the threshold is 35000 . It seems that there a size limition when initialize constant in CLR. Is there any configurable parameters can be used to increase this limition in C# compiler or .NET framework. Or I'm...
18
8646
by: vib | last post by:
Hi there, By chance, I came to learn that it is bad programming practice to initialize global variables at outside of programs. Is it that bad? In order to fullfil this, I had to declare them with const, but thereafter they are no longer variables. Just couldn't see the benefits of this practice. Any comments or advices are welcome. Thanks vib
10
2095
by: ibiza | last post by:
Hi, I have a class which will be used as a utility class (all its functions shared, no need to instantiate it, let's say just to calculate things) It needs a constant dictionary(of char, string) with 46 entries in it, that is used in all its shared functions. How can I instantiate it automatically only once, instead of creating it at each function call? thanks!
9
3431
by: Greg Buchholz | last post by:
/* While writing a C++ version of the Mandelbrot benchmark over at the "The Great Computer Language Shootout"... http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=all ....I've come across the issue that complex<double>'s seem quite slow unless compiled with -ffast-math. Of course doing that results in incorrect answers because of rounding issues. The speed difference for
4
2556
by: bob | last post by:
Why doesn't c++ let me initialize static members like this: class MySound { static CSoundManager* g_pSoundManager = NULL; };
6
19175
by: nik | last post by:
hello friends, a class having two const variables ,how can we initialize these variables
18
4213
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and use my specific constructor to initialize the class. How to do it without using malloc? Something like Point* pt = new Point; I want it to reserve the space for N points only, and not to call default constructor. I dont have a default...
0
8999
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
9575
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
9394
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
9338
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
9256
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
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6080
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();...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2223
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.