|
Thanks much! I was able to get the original Paul DiLascia HTMLCtrl and works awesome.
http://www.microsoft.com/msj/0100/c/c0100.aspx
|
|
|
|
|
Hi,
I'm looking for what I should use for a collection class which holds small objects of my own creation (all of the one class type.) Trouble is that the collection is expected to have up to 500000 objects in it.
What would be recommended for a collection class that minimizes the searching and retrieval time for so many objects in the collection?
Thanks,
Dave
|
|
|
|
|
It depends on how you want to access them. If you need to do lookups based on some key value, and the values do not need to be sorted, then you can use a hashmap, as it has constant time insertion, deletion, and retrieval.
If you need them sorted, then you could use a balanced tree, as that will have logN insertion/deletion/retrieval, and allows traversing the tree in order (keeping them sorted).
If you don't care how they are sorted, and don't need to do lookups, then you could use a simple linked list, or even an array if you know at the start how many items there will be.
If you can provide some more details with how you plan to use it, then it will be easier to recommend a specific collection to use.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Can anyone tell me why this code
#include <map>
std::map<std::string, int> foo;
int test_stl(std::string key)
{
return foo.find(key)->second;
} Gives me about a page of STL compilation errors in Visual Studio .NET?
Can anyone give me an example of working code that uses a hash_map or a map with an std::string key type?
Why couldn't Science, in the long run, serve
As well as one's uncleared lunch-table or
Mme X en Culottes de Matador? James Merrill
|
|
|
|
|
If you actually include the compile errors (or at least the first few), then it will make it a lot easier to determine what the problem is.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Looks like you just need to #include <string> :
#include <map>
#include <string>
std::map<std::string, int> foo;
int test_stl(std::string key){
return foo.find(key)->second;
}
- Mike
|
|
|
|
|
Duh! Thanks for setting me straight.
|
|
|
|
|
Hello everybody,
Here is my problem.
I wrote a program that does a statistical analysis, allocating large quantities of memories (3-400 MB) dynamically, and then performs cycles of calculations on the data.
At the end of each cycle, the program opens 2 files in sequence and writes the results to the disk.
With the first file there is no problem, with the second everything goes well for 20-30 cycles (on average, but the figure varies), when the fopen() that should open the file fails, returning a null pointer. If I try to make it open the same file (which is always the same file that it opened without problems for the first 20-30 cycles) passing to the fopen the name in “” instead of passing a variable, it still doesn’t open it.
If I give it a wayout letting it open another file somewhere else, it succeeds and goes on.
At the next cycle, it reopens the old file without problems.
It is as the write permission on that file were temporarily altered in a cycle, to be brought back to their original values in the next cycle.
The problem occurs with 3 different compilers (borland, Visual C++, mingw) and on 2 operating systems (windows NT e windows ME) , running on 2 different machines (both pentium)
I tried to launch the program from the Visual C++ debugger with all the cheks activated, putting also checks on the heap (functions _CrtMemCheckpoint, _ASSERTE( _CrtCheckMemory( ) )), but apparently there is no memory corruption problem.
Here is the function savememory where the error occurs.
void Sieve::savememo(void)
{
int lr,nd,i,j,b,var1,* fp2;
Node * ndp;
fp = fopen(MEMORYFILE,"w");
fprintf(fp,"\n%d",cyc);
for (lr=1; lr<LAYERS; lr++) {
fprintf(fp,"\n\nLR %d",lr);
for (nd=0; nd<nn[lr]->dimlr; nd++) {
ndp = nn[lr]->nodes[nd];
fprintf(fp,"\n%3d) ; %.3f ;",nd,ndp->score);
for (i=0; i<MAXIPNDS; i++) {
fprintf(fp," [%3d", ndp->memo.inar[i].ndnr);
fprintf(fp," %5.2f", ndp->memo.inar[i].wht);
fprintf(fp," (%3d", ndp->memo.inar[i].spc.x1);
fprintf(fp," %3d)", ndp->memo.inar[i].spc.x2);
var1 = (int)ndp->memo.inar[i].spon;
fprintf(fp," %d] ;", var1);
}
fprintf(fp," [%5.2f -1] ;", ndp->memo.bias);
fprintf(fp," (%2d %2d)", ndp->memo.a.x1,ndp->memo.a.x2);
fprintf(fp," (%2d %2d)", ndp->memo.b.x1,ndp->memo.b.x2);
}
}
if (fclose(fp))
printf("Error closing file\n");
#ifdef DEBUG2
printf("AFTER WRITE MEMORYFILE I AM! \n");
printf("\n%s %d\n", DNAMEMFILE, cyc);
#endif
fp = fopen(DNAMEMFILE,"w");
#ifdef DEBUG2
printf("\nfp: %p\n", fp);
if (fp == NULL)
fp = fopen("C:\\ZEUG\\ZOS\\MPXVC\\IOX\\MPXDNA0.TXT","w");
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\MPXVC\\IOX\\MPXDNA2.TXT","w");
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\MPX\\IOX\\MPXDNA3.TXT","w");
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\FILE01.txt","wt");
printf("AFTER fopen(DNAMEMFILE) I AM! \n");
#endif
for (lr=1; lr<LAYERS; lr++)
for (nd=0; nd<nn[lr]->dimlr; nd++) {
fprintf(fp,"\n\nlr %d nd %d dimpop %d\n",lr,nd,
nn[lr]->nodes[nd]->popp->dimpop);
for (j=0; j<DIMPOP; j++) {
fprintf(fp,"\n%5.3f %5.3f",nn[lr]->nodes[nd]->popp->guys[j].score,
nn[lr]->nodes[nd]->popp->guys[j].dd);
for (b=0; b<DIMDNA; b++) {
var1 = (int)nn[lr]->nodes[nd]->popp->guys[j].dna[b];
fprintf(fp," %d",var1);
}
}
}
fclose(fp);
#ifdef DEBUG2
printf("AFTER WRITE DNAMEMFILE I AM! \n");
#endif
}
Help, I’m getting crazy!
Thank you
Alex
|
|
|
|
|
Hi Alex,
You aren't testing whether the second fclose() succeeds. It may be that the value of fp has been trashed by your for loops. You could printf fp after the close or better still inspect it in the debugger.
Your code hasn't displayed correctly because < and/or > signs are missing. You need to use the Formatting bar to add these.
I'd try remove the code between the fopen/fclose and repeat the test and see what happens. Also inspect why the fopen is failing more closely. perror() might be of use here and the CRT global errno.
Hope that helps.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Neville,
That's what I did: I placed a GetLastError right after the test on the pointer of the fopen() and the result is error code = 32, which on my system means: "impossible to access the file, file is used by another process."
In additon, I noticed that, if I wait for a while (in the deubugger), the file (the same file, with the name unchanged) becomes available again and the fopen succeeds. So this would be an easy wayout I only coud be sure that no major problem (like dangling pointers or the like) is threatening the correctenss of the application results.
Anyway, I am trying to figure out some possibilities:
1. Is it possible that some system processes or not-system processes (I am thinking at the Kazaa stuff which I once downloaded - now I deleted it but I notice that, when I connect to the internet, an icon "connected" in the Kazza style appears at the bottom of the screen).
2. The file was not closed properly at the last cycle and so it is still marked as "used". In this case should be seen as used bu the same process, not by another one.
Now I am going to check out the result of the second fclose() as you already suggested.
What do you think?
Alex
|
|
|
|
|
Help...
I'm writing a "simple" DLL that should be capable of accepting a varaible as a dosptr (dos pointer) which would point to some text, modify it and return the modified text.
It seems that the pointer is being interpreted ok but I cant seem to return a revised variable to the calling app, well not without crashing it anyway.
Has anybody go any ideas ???
Cheerz
Juglugs
|
|
|
|
|
A dos pointer (as you put it) is just a standard C string pointer (char*) and these are passed to DLLs all the time.
The question are:
What is the DLL doing with the string?
Are you telling the DLL how much space it has to work with?
Are you sure the DLL is not over-running the buffer?
Are you passing a static or const string?
Is the DLL written using C or C++?
You could pass the string along with a seperate buffer (+size of buffer) to store the resulting string in, but that should not be needed.
In general calling a function/method in DLL is just like calling a function in your own code or one of the standard C/C++ libraries.
Trust in the code Luke. Yea right!
|
|
|
|
|
The DLL Should be just concatenating it with another string.
No im not telling the DLL how much space it has to work with.
shouldnt be overrunning the buffer.
static or const dunno the base app cannot pass strings as such just
a dosptr using somet like dll_call whichdll stack "P" var.
C++
|
|
|
|
|
Depends on what type of program is calling the dll function. You typically cannot realloc the string, nor change the length of the string if calling from VB.
onwards and upwards...
|
|
|
|
|
Hi!
I’ve noted that some wave editor programs (e.g. Wavelab 4.0) displays wave files in a very attractive fashion. Instead of plotting the xy values (time vs intensity) by simply connecting each two consecutive points with straight lines, they draw the envelope of the wave (upper and lower parts) and then fills the inner part.
Any idea about the algorithm they are using to produce such a nice plots?
Thanks,
Carlos
|
|
|
|
|
I have a derived CRichEditCtrl making use of the rich edit DLL RICHED20.DLL in a Dialog based application as a custom control and am trying to implement the "Select All" functionality found in the standard Edit menu of most applications. I tried using SetSel(0,-1) to select all the text in the RichEdit Control but it doesn't appear to work. Maybe I am going about this the wrong way, my desired behavior would be to have all of the text highlighted. How would I go about doing this based on my situation?
|
|
|
|
|
I am trying to create a pointer to a struct, but I keep getting errors.
I have been converting a *.c file to c++ and I am not too familuar with C.
I need to know the size of each one so I know what offset in memory to access the data.
i.e. if the header is 16 bytes long then I know anything larger than 16 bytes is the data values that I need.
I want to be able to access
SimSignal->Min[i];
SimSignal->Max[i];
SimSignal->Value[i];
SimSignal->Name[i];
SimSignal->Unit[i];
All of this data is related to one another.
I hope this makes sense.
Thanks for the help,
Steven
<br />
#define SIMHEAD_ADR 0x40 //This is the hardcoded address of the SimHeader (only hard coded address to RFM)<br />
<br />
<br />
struct TSimHeader<br />
{<br />
int SimWriteFlag; <br />
int DisplayReadFlag; <br />
int SignalCount; <br />
int SimStatus;<br />
};<br />
<br />
<br />
struct TSimSignal<br />
{<br />
double Min[88];
double Max[88];
double Value[88];
char Name[88];
char Unit[88];
};<br />
<br />
<br />
<br />
<br />
TSimHeader* SimHeader= SIMHEAD_ADR;<br />
TSimSignal* SimSignal= SimHeader+sizeof(TSimHeader);<br />
<br />
<br />
d:\.....h(42) : error C2258: illegal pure syntax, must be '= 0'
d:\.....h(42) : error C2252: 'SimHeader' : pure specifier can only be specified for functions
d:\.....h(43) : error C2065: 'SimHeader' : undeclared identifier
|
|
|
|
|
You left off a } somewhere. The compiler thinks it's still in a struct definition when it sees SimHeader = SIMHEAD_ADR and thinks you're declaring a pure-virtual function.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Actually, you need to prefix the type specifier with the keyword struct.
ex:
struct TSimHeader* SimHeader= SIMHEAD_ADR;
struct TSimSignal* SimSignal= SimHeader+sizeof(TSimHeader);
onwards and upwards...
|
|
|
|
|
Michael Dunn is probubly right about the error messages you received.
But you seem to have a few other problems:
TSimHeader* SimHeader= (TSimHeader*)SIMHEAD_ADR;
TSimSignal* SimSignal= (TSimSignal*)(SimHeader+1);
// This last is equivalent to
TSimSignal* SimSignal= (TSimSignal*)((char*)SimHeader+sizeof(TSimHeader));
//or
TSimSignal* SimSignal= (TSimSignal*)(SimHeader[1]); // Bad, but should work
Trust in the code Luke. Yea right!
|
|
|
|
|
Does anyone know how to install the resource editor. It does not show up in the Add-in manager. It has a batch file and when I click it it seems to install, but I can't use that editor.
|
|
|
|
|
I get the following errors when I declare this struct.
<br />
struct SimSignal<br />
{<br />
double Min;
double Max;
double Value;
char[88] Name;
char[16] Unit;
};<br />
<br />
d:\........h(17) : error C2059: syntax error : '['
d:\........h(17) : error C2238: unexpected token(s) preceding ';'
Looks right to me.
Any Ideas?
Thanks,
Steven
|
|
|
|
|
|
thanks,
I have been converting a *.c file to c++.
steven
|
|
|
|
|
I`m sorry but is the same in c and c++;););)
|
|
|
|
|