|
For this example, map is faster. But are you using Debug mode for your timings? I got a factor of 12 difference in debug mode, 3 in release mode.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i forgot switching to release mode might make a difference. Though the map stills performs faster with all speed optimazations enabled in release mode. I tested for a million elements and ten thousand, the speed difference of a vector and map seems more marginal when retrieving the values of a million elements but the map performs faster in both cases.
Here's what I got for ten thousand :
vector map
0.00141 0.00093
0.00139 0.00085
0.00156 0.00085
seconds
|
|
|
|
|
I suspect the other thing that can affect the performance is the key type.
All I know is that for my particular application, maps were slower
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I guess it's useful to know both methods then.
i'll use a map for the project i'm doing at the moment.
thanks for your help
|
|
|
|
|
This program runs fine except when I try to delete/remove/erase an item as indicated below. No matter what I've tried with erasethe program crashes.
Could someone please help here.
Thanks
Alan Kurlansky
PS. When I cut and pasted some characters got changed. I hope I fixed alll of them.
// MultiMap.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
using namespace std;
void testmultimap();
#include <tchar.h>
struct ASK {
int ival;
string key;
};
multimap<string, ASK *> mymm2;
multimap<string, ASK *>::iterator iter;
pair<multimap<string, ASK> ::iterator,multimap<string, ASK *>::iterator> ret;
int _tmain(int argc, _TCHAR* argv[])
{
testmultimap();
return 0;
}
//----------------------------------------------------------------------------------------------------------------
void testmultimap()
{
string key;
key.clear();
key.append("a");
ASK * Iptr = new ASK;
Iptr->ival = 10;
Iptr->key.clear();
Iptr->key.append(key);
mymm2.insert(pair<string,ASK *>(key, Iptr));
key.clear();
key.append("a");
Iptr = new ASK;
Iptr->ival = 20;
Iptr->key.clear();
Iptr->key.append(key);
mymm2.insert(pair<string,ASK *>(key, Iptr));
key.clear();
key.append("b");
Iptr = new ASK;
Iptr->ival = 30;
Iptr->key.clear();
Iptr->key.append(key);
mymm2.insert(pair<string,ASK *>(key, Iptr));
key.clear();
key.append("a");
ret = mymm2.equal_range(key);
int cnt(0);
for (iter=ret.first; iter!=ret.second; ++iter) {
printf("ival:%d key:[%s]\n", (*iter).second->ival, (*iter).second->key.c_str() );
// delete this single entry
// mymm2.erase(????);
}
printf("\n");
printf("2nd pass after 'a' erase\n");
ret = mymm2.equal_range(key);
for (iter=ret.first; iter!=ret.second; ++iter) {
printf("ival:%d key:[%s]\n", (*iter).second->ival, (*iter).second->key.c_str() );
}
printf("\n");
key.clear();
key.append("b");
ret = mymm2.equal_range(key);
for (iter=ret.first; iter!=ret.second; ++iter) {
printf("ival:%d key:[%s]\n", (*iter).second->ival, (*iter).second->key.c_str() );
}
printf("\n");
}
//----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
When you modify the contents of a container, the iterators become invalid.
I believe that is what is happening here.
|
|
|
|
|
Thanks! I made a change that reflects what you said and all seems to be working now.
|
|
|
|
|
Hi,
I've run into a problem with the TransparentBlt function.
When I use TransparentBlt with a 24-bit bitmap it correctly masks the specified transparent color, but when I call it for a 4-bit or 8-bit bitmap, it doesn't make that color transparent.
For example, if I have a bitmap with a large rectangle of MAGENTA color and give RGB(255,0,255) as the last parameter in the function, the magenta is still there with a 4-bit bitmap, but it's masked with the 32-bit one.
This problem might be because 256-color/16-color bitmaps don't use RGB values. May be they use palettes somehow.
Can anyone help with that.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: This problem might be because 256-color/16-color bitmaps don't use RGB values. May be they use palettes somehow.
You are correct, obviously you cannot put RGB(R, G, B) into 4 or 8 bits. The early bitmap types could select a subset of the RGB spectrum and did so by first selecting a palette of colours and then using the color value as an index into the palette set. So the bottom line is that you cannot use all the new functionality with the old 16/256-colour bitmaps.
|
|
|
|
|
Richard MacCutchan wrote: You are correct, obviously you cannot put RGB(R, G, B) into 4 or 8 bits. The early bitmap types could select a subset of the RGB spectrum and did so by first selecting a palette of colours and then using the color value as an index into the palette set. So the bottom line is that you cannot use all the new functionality with the old 16/256-colour bitmaps.
Yes, we can!
|
|
|
|
|
Rozis wrote: Yes, we can!
How?
|
|
|
|
|
Richard MacCutchan wrote: The early bitmap types could select a subset of the RGB spectrum and did so by first selecting a palette of colours and then using the color value as an index into the palette set.
Can you give an example for using a palette?
How do I construct one, and do I select it into the DC with SelectObject?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: Can you give an example for using a palette?
I'm afraid I have not used this functionality for years so can only vaguely remember how it all fits together. You can probably find some information via Google, or Rozis has made a suggestion below as to how to convert to 24-bit.
|
|
|
|
|
The book Programming windows of charles Petzhold explains it pretty well
|
|
|
|
|
Rozis wrote: The book Programming windows of charles Petzhold explains it pretty well
I agree, all his books are really good. The version I had was Programming windows 3.1, which is a bit old now!
|
|
|
|
|
Maybe i can help you...
sashoalm wrote: This problem might be because 256-color/16-color bitmaps don't use RGB values. May be they use palettes somehow.
Only 24-bit bitmaps use no colortable, each pixel is 3 bytes in memory being 8 bits for red, 8 for green and 8 for blue. Transparency is implemented as an extension on this: instead of 3 bytes it uses 4 bytes for a pixel (8 bits for transparency level called 'Alpha'). 256- and 16-color bitmaps use a colortable.
TransparentBlt() has 2 levels of transparency: global and per pixel. Global transparency will make all your pixels - for example - 50% transparent. This only works for 24- and 32-bits bitmaps.
Per pixel transparency uses the setting of the alpha. So a 32-bitmap is required. With this you can set the transparency per pixel. One thing to know is that pixel-transparency expects your values for RGB are 'pre-multified', meaning:
alpha:=.. // alpha holds the alpha of the pixel
factor:=alpha/255
r:=r*factor
g:=g*factor
b:=b*factor
I'm not sure what your problem exactly is but i bet the solution is to 'transform' the bitmaps to a 24-bit version. With CreatecDIbitmap() you can do this...
Rozis
|
|
|
|
|
|
vtech22 wrote: As a final project...
...and have no clue were to even start
So where did you start with the other non-final projects?
Who gave you this assignment?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
vtech22 wrote: ...they just told me what to do...
And you don't have access to any of those past projects?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
nope after each assignment is done she takes them and thats the last we see of any of them (personally i think she's not that great of a teacher anyway all she ever said was read the book and that deffinitly doesnt help when you already dont know whats going on)
|
|
|
|
|
So none of this looks familiar:
void main( void )
{
printf("1) Option 1\n");
printf("2) Option 2\n");
printf("3) Option 3\n");
printf("4) Some other menu\n");
printf("5) Exit\n\n");
int nChoice = 0;
do
{
printf("Option: ");
scanf("%d", &nChoice);
} while (nChoice >= 1 && nChoice <= 4);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
vtech22 wrote: personally i think she's not that great of a teacher
You'd be surprised (but I wouldn't) how often this excuse is trotted out as some sort of reason why we should do other people's work. Maybe you should have taken her advice and read some books, or even the notes you made of each assignment.
|
|
|
|
|
|
You're in college now studying computers in some technical fashion and didn't already know simple programming when you started? Way behind the curve.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|