471,052 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,052 software developers and data experts.

Optimizing away a class as best as possible?

Hi All,

I've got a small logging class that I would like to have a way to
optimize away as much as possible with the minimum of macro trickery.
I've got working code, but not having done C++ much for a few years, I
have the feeling that this code might not be the best. I'd like to be
able to have different source files compile in different states so that
the high performance cores can optionally be built with logging
dissapearing as much as possible while retaining logging in other parts
of the system. This works on 4.0.1, but that doesn't mean that what I
am doing is a good idea :)

Here is my first try at a header for a small class that can pick up the
location of a log call via a macro, which should be a pretty simple
example of what I am trying to do. I am bothered by having different
prototypes for each mode, but looking at the assembler code shows that
when NLOG is defined, the most of the code for the Where class
evaporates. Anyone want to shoot this code to pieces? :) Should I be
returning references to const static values?

The end goal is to write some think this and then have it optionally
get yanked out of the code with NLOG... I have the logger working
nicely, now I am going for the optimization potential.

logger << WHERE << " some state " << i << " " << j << endl;

#define WHERE Where(__FILE__,__LINE__,__FUNCTION__)
#include <string>
#include <iostream>

#if !defined(NLOG)
class Where {
Where(const std::string &_file, const int _lineno, const
std::string &_function);
inline std::string const &getFile() const {return file;};
inline int const &getLineno() const {return lineno;};
inline std::string const &getFunction() const {return function;};
std::string file;
int lineno;
std::string function;

Where::Where(const std::string &_file, const int _lineno, const
std::string &_function)
: file(_file), lineno(_lineno), function(_function) {} // Nothin


// if gcc
#define UNUSED __attribute((__unused__))
class Where {
Where(UNUSED const std::string &_file, UNUSED const int &_lineno,
UNUSED const std::string &_function) {};
inline std::string getFile() const {return std::string("unknown
inline int getLineno() const {return -1;};
inline std::string getFunction() const {return std::string("unknown
#endif // NLOG for where

Jul 23 '06 #1
0 972

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by A Future Computer Scientist | last post: by
4 posts views Thread by J. Campbell | last post: by
8 posts views Thread by Hagen | last post: by
5 posts views Thread by Daishi Harada | last post: by
5 posts views Thread by Tony | last post: by
24 posts views Thread by Richard G. Riley | last post: by
26 posts views Thread by jaysome | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.