|
This is the C++ forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I would like some advice on which STL container is best given the following requirements
* I need to store in memory a collection of unsigned ints
* Only one thread will touch the collection
* Speed is critical for add/find/remove
* I need to add to this collection, usually I will be adding a continuous range (eg 10, 11, 12, 13, 14)
* I need to find out if a specific value is in the collection
* I need to remove specific values
* I would like to minimise memory usage by allocating storage for the most common size of this collection at startup, have the collection expand itself if nessasary (without moving existing items) but never shrink itself
Is there an STL container that can meet all of these or do I need to make my own?
|
|
|
|
|
Will you be adding elements just to the end, at the start and end or at any location?
Will you be removing elements just at the end, at the start and end or at any location?
Do you need to preserve the insertion order?
Do you need to be able to iterate over the collection in numerical order?
Are multiple copies of the same value allowed?
Steve
|
|
|
|
|
Stephen Hewitt wrote: Will you be adding elements just too the end, at the start and end or at any location?
Elements will always be unsigned int's. Every element I add will be greater than all the elements already in the collection. If the collection has {1, 7, 8} I could add 9 or 45 etc but never 6. Im not interested in their location in the collection but Im guessing a sorted collection will give me faster lookup
Stephen Hewitt wrote: Will you be removing elements just at the end, at the start and end or at any location?
Any location
Stephen Hewitt wrote: Do you need to preserve the insertion order?
Nope
Stephen Hewitt wrote: Do you need to be able to iterate over the collection in numerical order?
Nope
Stephen Hewitt wrote: Are multiple copies of the same value allowed?
Nope
|
|
|
|
|
The easiest choice would seem to be a std::set :
- Search time is at most O(log2(N)). Use the set 's member functions to do the searching and not those from <algorithm>.
- The collection itself will enforce uniqueness.
- Insertion/deletion at any point is fast and not related to the number of elements in the container.
Steve
|
|
|
|
|
Stephen Hewitt wrote: The easiest choice would seem to be a std::set:
- Search time is at most O(log2(N)). Use the set's member functions to do the searching and not those from <algorithm>.
- The collection itself will enforce uniqueness.
- Insertion/deletion at any point is fast and not related to the number of elements in the container.
Thanks mate
|
|
|
|
|
Stephen Hewitt wrote: he easiest choice would seem to be a std::set:
oof topic.. is there any way to stop map to have sorted data.. i come across third argument which use std::less by default to for sorting the inserted value but i am not able to find and replacement.. any comment or pointer is very valuable!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You can change the sorting criteria but the map must be sorted. What’s more the sorting criteria must define a strict weak ordering.
Steve
|
|
|
|
|
Stephen Hewitt wrote: What’s more the sorting criteria but define a strict weak ordering.
thanks for your comment sir!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I am porting a dll to VC++2005. While building i am getting the following error
Error 5 error C2440: '=' : cannot convert from 'int (__cdecl *)(NC_string *)' to 'int (__cdecl *)(void)'
in the code.
case NC_STRING :
xlen_funct = NC_xlen_string ;(i am getting error here)
break ;
Any help will be appreciated.
Regards, Eswari
|
|
|
|
|
The function NC_xlen_string has an argument of type NC_string* but the type of the function pointer xlen_funct expects a function with no arguments.
Steve
|
|
|
|
|
A little bit more information would be usefull.
What is NC_xlen_strin ? And what is xlen_funct ?
By the error description it seems that it is a function, am I right ? Then I don't see at all what you are trying to do. Can you explain ?
|
|
|
|
|
both are functions. first one is a int (*xlen_funct)(void).
SEcond one is
extern int NC_xlen_string PROTOTYPE((
NC_string *cdfstr
));
and this is where these are being used.
case NC_STRING :
xlen_funct = NC_xlen_string ;
break ;
which cast i have to use and how?
Regards, ESwari
|
|
|
|
|
subramanyeswari wrote: which cast i have to use and how?
You can't cast from one into the other. They don't have the same prototype (one is accepting a parameter and the other does't).
But why would you ever do such a thing ?
By the way, what is the macro PROTOTYPE doing ?
|
|
|
|
|
Do ***NOT*** cast. The compiler is making a valid statement and casting the problem away will turn a compile time error (good) into a runtime error (bad). The real problem is your function pointer is of the incorrect type (from what I've seen so far).
Steve
|
|
|
|
|
Show me the type of len_funct . Therein lies the error (from what I've seen so far).
Steve
|
|
|
|
|
h, i gotta question. i built lux meter base on pc and use adc 12 bit, parallel port, and vb programing. could u help me to give some code to finish this project!
i fond a problem when i start to read the input signal.
sexpistols
|
|
|
|
|
First: This is the Visual C++ / MFC discussion board. So it's not for VB questions.
Second:
mrizki wrote: i fond a problem
What problem? Don't expect us to mind-read!
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
kakan wrote: Don't expect us to mind-read!
he he he! he wanted you to be god!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
mrizki wrote: built lux meter base on pc and use adc 12 bit, parallel port, and vb programing. could u help me to give some code to finish this project!
how much you have coded!... do you designed something
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
How to disbel the popup menu that was displayed when window button (start menu) is clicked (in keyboard)
|
|
|
|
|
prathuraj wrote: How to disbel the popup menu that was displayed when window button (start menu) is clicked (in keyboard)
system level hook!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
i have tried in the follwing way to disable left window key
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_LWIN )
{
pMsg->wParam = NULL;
}
But it does not disabled the key what is a problem.
|
|
|
|
|
The code that you posted will only intercept keystrokes when your app has the input focus. When you click on the Start button, you are shifting focus away from your app, and so you will never see those keystrokes. As ThatsAlok said, you need to do this on a system-wide basis.
Best wishes,
Hans
|
|
|
|
|
Hi everybody.
I am using this cite first time, so I am not aware of the specific ways of asking any question.
My problem is that I have a file published by sharing the folder containing that file. I don't want to allow other users, who will access that file through LAN to delete and to copy. But they should be able to read the contents of that file.
I tried using the CreateFile API with no sharing mode as one of the argument but if I do so then nobody is able to open it.
Is there any way to achieve this?
Pavan Deshpande
|
|
|
|