Integer Pool

  • Thread starter Thread starter Trecius
  • Start date Start date
T

Trecius

Hello, Newsgroupians:

I have a method that requires me to specify a client handle when I create
the object. The object prototype is as follows...

void Server.CreateMonitor(string strName, int nClientHandle);

When I create the monitor, I have specify a client handle. Therefore, when
using other methods that came with the library, all I need to do is specify a
client handle.

I'd like to create a "handle pool" that will allow me to grab an integer
from the pool and pass that into the function. This is synonymous to
creating a handle in Win32; the handle is unique. Does anyone have any good
resources as to where I can find some good information regarding creating a
pool that will do this for me? I've been doing some searching, but all I can
find is "thread pools" and not "handle pools." Perhaps my terminology is
incorrect?

How does Windows do it to create handles and make them unique?

Thank you,


Trecius
 
If there is a direct mapping of the Handle with some value, like it's
type (which is not very clear in your description) you can use a
Dictionary like this

Dictionary<int, int> handles = new Dictionary<int, int>();
or
Dictionary<string, int> handles = new Dictionary<string, int>();

Where the key will be the type of handle and it's value will be the
actual handle
Then you can add/set the handle like this

handles["FileHandle"] = xyz;

and you will retrieve or use it like this
int handle = handles["FileHandle"];

Thanks & Regards,
Ashutosh
 
Thank you, but it's not quite what I'm looking for. I may not know the
strName until runtime. For example, if I were to just start the program, and
I have one element. I want to get one item from the pool -- maybe it will be
1. Now I know that no other item can be 1. Next, if I have another element
at run time, I want to get another handle. I call the pool for another
handle, and it gives me one -- maybe it will be 2. Now maybe I'm done with
the first handle and no longer require it, so I release the handle back to
the pool, so if I call the pool for another handle, it may return a 1 to me
because I had already release it.


Trecius

Ashutosh Bhawasinka said:
If there is a direct mapping of the Handle with some value, like it's
type (which is not very clear in your description) you can use a
Dictionary like this

Dictionary<int, int> handles = new Dictionary<int, int>();
or
Dictionary<string, int> handles = new Dictionary<string, int>();

Where the key will be the type of handle and it's value will be the
actual handle
Then you can add/set the handle like this

handles["FileHandle"] = xyz;

and you will retrieve or use it like this
int handle = handles["FileHandle"];

Thanks & Regards,
Ashutosh
Hello, Newsgroupians:

I have a method that requires me to specify a client handle when I create
the object. The object prototype is as follows...

void Server.CreateMonitor(string strName, int nClientHandle);

When I create the monitor, I have specify a client handle. Therefore, when
using other methods that came with the library, all I need to do is specify a
client handle.

I'd like to create a "handle pool" that will allow me to grab an integer
from the pool and pass that into the function. This is synonymous to
creating a handle in Win32; the handle is unique. Does anyone have any good
resources as to where I can find some good information regarding creating a
pool that will do this for me? I've been doing some searching, but all I can
find is "thread pools" and not "handle pools." Perhaps my terminology is
incorrect?

How does Windows do it to create handles and make them unique?

Thank you,


Trecius
 
Handles are not just any items that you put into a pool and use any
available one.

Each handle (finally) maps to a kernel object in the system. So I am not
sure if your usage is correct.

If all your handles are for a single type of object and you are not
bothered about a particular instance, then you can use a Stack or a
Queue or List to store the handles.

Thank you, but it's not quite what I'm looking for. I may not know the
strName until runtime. For example, if I were to just start the program, and
I have one element. I want to get one item from the pool -- maybe it will be
1. Now I know that no other item can be 1. Next, if I have another element
at run time, I want to get another handle. I call the pool for another
handle, and it gives me one -- maybe it will be 2. Now maybe I'm done with
the first handle and no longer require it, so I release the handle back to
the pool, so if I call the pool for another handle, it may return a 1 to me
because I had already release it.


Trecius

:

If there is a direct mapping of the Handle with some value, like it's
type (which is not very clear in your description) you can use a
Dictionary like this

Dictionary<int, int> handles = new Dictionary<int, int>();
or
Dictionary<string, int> handles = new Dictionary<string, int>();

Where the key will be the type of handle and it's value will be the
actual handle
Then you can add/set the handle like this

handles["FileHandle"] = xyz;

and you will retrieve or use it like this
int handle = handles["FileHandle"];

Thanks & Regards,
Ashutosh
Hello, Newsgroupians:

I have a method that requires me to specify a client handle when I create
the object. The object prototype is as follows...

void Server.CreateMonitor(string strName, int nClientHandle);

When I create the monitor, I have specify a client handle. Therefore, when
using other methods that came with the library, all I need to do is specify a
client handle.

I'd like to create a "handle pool" that will allow me to grab an integer
from the pool and pass that into the function. This is synonymous to
creating a handle in Win32; the handle is unique. Does anyone have any good
resources as to where I can find some good information regarding creating a
pool that will do this for me? I've been doing some searching, but all I can
find is "thread pools" and not "handle pools." Perhaps my terminology is
incorrect?

How does Windows do it to create handles and make them unique?

Thank you,


Trecius
 
Back
Top