> Coming from c# world its sometimes hard to find my way in the C/C++ world
so i will try to take the shame and ask the OSR gods for help 
Question 1
Can i have a dynamic size collection that can be re sized whenever needed.
Currently in my driver i can only have an initially allocated array of
specified size containing handles.
I have something like this PVOID processes[128];
Also i wonder how can i check if the array at specified index is
populated. Should i check if it equals NULL?
Is it really a PVOID or is it a pointer to a known type, in which case
that typename would be a better chioce.
C has no provision for dynamic arrays. C++ collections do not work well
in the kernel because they can throw exceptions, which are currently not
supported in the kernel. You could write your own collection, but you
would have to be certain everything you do is compatible with what C++ in
the kernel is capable of supporting.
As already pointed out, lists are a better choice under most
circumstances. If there is no order relationship among the elements,
adding a new item is a fixed constant time. Allocating the space to
represent the item is the major performance cost, and Microsoft is
constantly improving the performance of the kernel allocator, so other
than actually measuring the performance, it is hard to estimate. If there
is an ordering relationship, a list is potentially very slow, but the
name of your variable suggests that it is more likely an unordered
collection of values. Adding to a list can be reduced to O(log2(n) + k)
where k is generally a small constant, but that is a complex algorithm I
donât want to go into here if you donât need it, and I suspect you donât.
You did not give any context as to where that declaration appears. It
might be a local variable (not a great idea because of the limited stack
space that drivers have, in your device extension (generally the best
choice) or a global (generally, in fact, nearly always, the worst possible
place). In the latter two choices, you must either guarantee, by how your
code works, that it cannot ever be accessed from multiple threads in a way
that would find the contents would be invalid due to concurrent access, or
provide a lock appropriate to the IRQL level and time constraints you must
live with. In general, a spin lock would suffice, but then you must not
call any functions from within the spin lock that are not valid at
DISPATCH_LEVEL. So it is difficult to give an answer to the question
without knowing a lot more about the problem domain than you have given.
joe
NTDEV is sponsored by OSR
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer