|
I read an article in CUJ or DDJ (can't remember which) last fall which dealt with these performance problems.
One solution (using storage trade-offs) was to create a std::string compatible class called something like fixed_string. fixed_string would then implement the string using a fixed length char array. You got the best of both worlds: speed and the nice std::string interface.
The article also mentioned how you could pool these strings to optimize the performance even more (mostly for threaded environments).
I'm sorry I can't give you a correct reference to the article, my magazines are at home, and I'm not online at home anymore
Sonorked as well: 100.13197 jorgen
FreeBSD is sexy.
|
|
|
|
|
Exactly. Get the safe deallocation (if your strings are that big). Maybe even buffer overrun if you so decide it is needed.
As I have always said, know what tools are available and understand the costs involved with each.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
You should also consider the use of std::vector<char>
To the best of my knowledge, the std requires that elements should be allocated contiguosly (not sure)
Consider
std::vector<char> buffer;
buffer.resize(n);
legacy_function(&(buffer.at(0)),buffer.size());
Comments:
I am not comparing anything. Just another "tool/way" to do things that is worth be aware of
Regards,
R.
|
|
|
|
|
To the best of my knowledge, the std requires that elements should be allocated contiguosly (not sure)
The standard does not guarantee this, but later on this was perceived as a defect in the standard itself and a so called "tecnhical corrigendum" was issued in 2000 that fixes the error. Moreover, every compiler known so far stores vectors contiguously (and future ones are compelled to follow the corrigendum as well as the standard). So the moral is: contiguous vectors are a standard guarantee as of today, and every compiler implement them this way.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
corrigendum
Damn, had to look that one up.
Either...
1. I am stupid
2. Or in the US we use a different term. I guess I have always called them "errata"
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Standardese has its lingo, I guess. I find the word somewhat funny, too.
PS. If you allow me to go pedantic, for those of you with a leaning towards Latin, erratum (pl. errata) means "error", while corrigendum means something like "to be corrected" (pretty much the same, anyway.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Sort of like the words "feature" and "bug fix" in development.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi Joaquín,
Interesting. Maybe I'm too lazy, but how do you go about finding that kind of stuff out? What are your sources. We have ways of making you talk.
Nice,
Giles
Giles
|
|
|
|
|
You just follow discussions. Usenet newsgroups like comp.lang.c++.moderated and comp.std.c++ are two very good sources. C/C++ Users Journal also contains some info.
|
|
|
|
|
When run through the command line my program prints a usage message and then I type in the file name I want it to perform fopen call on. It then performs writes to this file.
When I click the icon I just get a quick flash on the screen. i tried checking the properties to see if I could change how the program is run but it will only let me view the general prperties.
|
|
|
|
|
Are you processing somehow the commandline parameters stored in argc and argv ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes I am taking an infile.txt and compression it it outfile.txt. under Huffman compression.
It works fine when I run it from the ms-dos command line but not when I double click the icon. Any ideas would be much appreciated.
|
|
|
|
|
Klara wrote:
Yes I am taking an infile.txt
Aha! That's where the error is. You assume that infile.txt is in the current directory. You forget that when you run from windows the current directory need not always be the executable's directory.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Yes, when I run it from the command line I always have to type
cd C:\pathname\ and then type Myprog.exe
Then the path is chnged to where the exe file is and then I can run Myapp.exe. The program then should print a usage message and I type infile(it is in the same location as the exe file) and I type the name of outfile which is placed in the same folder.
Any ideas how to fix the icon problem?
Thanks for your input though.
|
|
|
|
|
Klara wrote:
Then the path is chnged to where the exe file is and then I can run Myapp.exe. The program then should print a usage message and I type infile
So, basically the first thing your program does is to display a message on the console. Then it reads the name of the infile followed by the name of the outfile. Is that what it does?
And what you say is that you don't even get the prompt to enter the file name, correct?
Could you please post the relevant code snippets upto this point in your code?
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
I don't get a prompt unless I runn it through the commandline, so at least I know the program works.
The main() routine supplied here has the job of checking for valid input and output files, opening them, and then calling the compression routine. It expects to find a compression routine in another module. If the files are not present, or no arguments are supplied, it prints out an error message, which includes the Usage string supplied by the compression module. All of the routines and strings needed by this routine are defined in the MAIN.H header file. I have included some explanations of the various modules further down.
I don't get a prompt unless I runn it through the commandline. This is part of my main program.
*/ This is the usage message
Usage:DOHUFF infile.txt outfile.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitio.h"
#include "errhand.h"
#include "main.h"
void usage_exit( char *prog_name );
void print_ratios( char *input, char *output );
long file_size( char *name );
int main( argc, argv )
int argc;
char *argv[];
{
BIT_FILE *output;
FILE *input;
setbuf( stdout, NULL );
if ( argc < 3 )
usage_exit( argv[ 0 ] );
input = fopen( argv[ 1 ], "rb" );
if ( input == NULL )
fatal_error( "Error opening %s for input\n", argv[ 1 ] );
output = OpenOutputBitFile( argv[ 2 ] );
if ( output == NULL )
fatal_error( "Error opening %s for output\n", argv[ 2 ] );
printf( "\nCompressing %s to %s\n", argv[ 1 ], argv[ 2 ] );
printf( "Using %s\n", CompressionName );
CompressFile( input, output, argc - 3, argv + 3 );
CloseOutputBitFile( output );
fclose( input );
print_ratios( argv[ 1 ], argv[ 2 ] );
return( 0 );
}
/*
* This routine just wants to print out the usage message that is
* called for when the program is run with no parameters. The first
* part of the Usage statement is supposed to be just the program
* name. argv[ 0 ] generally holds the fully qualified path name
* of the program being run.
*/
void usage_exit( prog_name )
char *prog_name;
{
char *short_name;
char *extension;
short_name = strrchr( prog_name, '\\' );
if ( short_name == NULL )
short_name = strrchr( prog_name, '/' );
if ( short_name == NULL )
short_name = strrchr( prog_name, ':' );
if ( short_name != NULL )
short_name++;
else
short_name = prog_name;
extension = strrchr( short_name, '.' );
if ( extension != NULL )
*extension = '\0';
printf( "\nUsage: %s %s\n", short_name, Usage );
exit( 0 );
}
|
|
|
|
|
What's happening is that since argc < 3, your program displays the usage message and exits.
Right click on the icon of the execuatble in explorer. You should get a properties tab window. Select the "Program" tab. There will be an edit box where you are supposed to enter the full command line. If you have any arguments you should append those arguments to the full path of the executable.
Eg:- C:\abc\myexe.exe file1.txt file2.txt /r:100
Regards,
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Thanks for the help, I'm gonna try that out now.
|
|
|
|
|
Hey Nish,I'm still getting problems with this icon. When I right click on it I get the general properties only and nothing else. The check box is set to archive and there are no other tabs so I can't change the path name.
Any other ideas
|
|
|
|
|
Are you reading from a file, assuming it is in the same directory as the exe file? When you run it from windows the current directory might vary.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
As an aside, why on *earth* are you using fopen instead of iostreams ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I'm using fopen becuse its just what I'm used to, it's a school project and, we never learned anything about iosteams.
any ideas about the icon problem, its relly annoying me. When I set the active configurations of an ms-dos project should it be debug or release. Could this make a difference. I don't know what they are for.
|
|
|
|
|
Klara wrote:
I'm using fopen becuse its just what I'm used to, it's a school project and, we never learned anything about iosteams.
If you'll excuse me while I rant for a moment: this is precisely why there are so many bad programmers in the world, bad teachers. Why on EARTH would you teach someone C style file access instead of IOStreams ? Why do people get taught C style string handling instead of std::string ? Why ? Because they are being taught by C programmers trying to use C++ as a better C. It's not just C with classes anymore, and this style of teaching leads to bad coding habits, not to mention being harder to learn. Stroupstrup has said a lot about why C++ should not be taught this way, if only the academic world would catch up and stop teaching 1982 style programming.......
Klara wrote:
any ideas about the icon problem, its relly annoying me. When I set the active configurations of an ms-dos project should it be debug or release. Could this make a difference. I don't know what they are for.
The debug version requires debug versions of the librarys such as MSVCRT, which you most certainly need to fopen, so they will not run on machines that do not have a development environment on them. So you should compile for debug when you're writing the program ( it allows you to break and step through your code, reports memory leaks ( which are far more likely to happen in C than in C++ code ).
Is the problem that the program flashes up and disappears ? Maybe you need to put up a prompt to wait ? I'm sorry, I don't know how that is done in C.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
What switches should I specify to link.exe to generate a raw binary?
Also, can dumpbin disassemble a raw binary?
|
|
|
|
|
AFAIK you can only create PE's with link.exe. F.ex. how would you know where the different sections were using a "raw binary"?
|
|
|
|