473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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;

Thanks!
-kurt
#define WHERE Where(__FILE__,__LINE__,__FUNCTION__)
#include <string>
#include <iostream>

#if !defined(NLOG)
class Where {
public:
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;};
private:
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

#else
//////////////////////////////////////////////////////////////////////

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

Jul 23 '06 #1
0 1102

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: A Future Computer Scientist | last post by:
A question: Is it really important to think about optimizing the native code or optimizing it for P Code? Or does the code you write make a difference?
4
by: J. Campbell | last post by:
From reading this forum, it is my understanding that C++ doesn't require the compiler to keep code that does not manifest itself in any way to the user. For example, in the following: { for(int...
3
by: PWalker | last post by:
Hi, I have written code that I would like to optimize. I need to push it to the limit interms of speed as the accuracy of results are proportional to runtime. First off, would anyone know any...
8
by: Hagen | last post by:
Hi, I have a question that you probably shouldn´t worry about since the compiler cares for it, but anyways: When you run your compiler with optimization turned on (eg. g++ with -Ox flag) and...
5
by: Daishi Harada | last post by:
Hi, I'd like to get the 'get2' function below to perform like the 'get1' function (I've included timeit.py results). I'm not sure how to write 'mkget' to do achieve this, however, except to...
5
by: Tony | last post by:
Hi - I have a really massive stylesheet, and I want to trim it down to a more reasonable size. So, what I'm wondering is if anyone can recommend any decent online tutorials (preferred) or maybe...
24
by: Richard G. Riley | last post by:
Without resorting to asm chunks I'm working on a few small routines which manipulate bitmasks. I'm looking for any guidance on writing C in a manner which tilts the compilers hand in, if possible,...
26
by: jaysome | last post by:
Suppose I have something like this on a free-standing environment (where void main(void) is documented and well-defined): static int G_num_loops = 0; void main (void) { /* set up interrupts...
10
by: anon.asdf | last post by:
Here's a reminder of duff's device: /*************************************/ #include <stdio.h> #define STEP 8 #define MAX_LEN STEP*4+1 #define SOURCE_LEN 28
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.