473,804 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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__,__FUNC TION__)
#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(co nst std::string &_file, const int _lineno, const
std::string &_function)
: file(_file), lineno(_lineno) , function(_funct ion) {} // 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("un known
file");};
inline int getLineno() const {return -1;};
inline std::string getFunction() const {return std::string("un known
function");};
};
#endif // NLOG for where

Jul 23 '06 #1
0 1123

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

Similar topics

6
2877
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
2542
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 i = 0; i < 10; ++i){ std::cout << i << std::endl; for(int j = 0; j < 0x7fffffff; ++j){} } }
3
3336
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 resources that explains how to optimize code i.e. give some rules on c++ optimization? e.g. using memcpy to copy an array (which i have done). Also, what is the best sorting algorithm out there for sorting an array of of size 100 or less? I have...
8
1953
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 your program gets significantly faster than without, did you write bad code/ have a bad design? Cause what happens in those optimization steps is, I think, mostly
5
1669
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 use 'exec' - is that what would be necessary?
5
1334
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 a book about the subject? Of course, I can Google for "CSS optimization" and other such queries, but that doesn't necessarily mean the tutorials are any GOOD :) -- Which is why I'm asking your opinions.
24
3170
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, a compiler/underlying processor independant way : althought to be fair I cant see this stuff on anything other than x86, but who knows. I found some ok info here: http://www.eventhelix.com/RealtimeMantra/Basics/OptimizingCAndCPPCode.htm...
26
1593
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 */ /* ... */ for ( ; ; )
10
2441
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
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.