I have recently started making a C++ Wrapper of GTK+ (Nothing special, just wrapping everything into C++ classes for easy development, to be used in-house) and to cause minimum performance bloat to the already slow Gtk+ I used inline functions almost everywhere. Take a look at a few class functions...
class Widget : public Object
{
public: // A few sample functions. gwidget is the internal GTK+ widget.
void Show(void) { gtk_widget_show(GTK_WIDGET(gwidget)); }
void ShowNow(void) { gtk_widget_show_now(GTK_WIDGET(gwidget)); }
void Hide(void) { gtk_widget_hide(GTK_WIDGET(gwidget)); }
void ShowAll(void) { gtk_widget_show_all(GTK_WIDGET(gwidget)); }
public: // the internal Gtk+ widget.
GtkWidget* gwidget;
};
And although there is an almost non-existent performance bloat and the startup time and memory usage is exactly the same, the file size has increased dramatically. a C Gtk+ sample window generates 6.5 kb while a sample window using my wrapper generates 22.5 kb. , so I need a little advice. Should I continue using inline functions? I want my apps to be efficient and I can compromise a little on file size like I can take it even if a 6.5 kb C GTK+ program generated like 400-500 kb using my wrapper but NOT MORE. I don't want my wrapper to produce HUGE EXES like wxWidgets or MFC. So is it worthwile to use inline functions or should i use normal ones?
NOTE: all my functions only take up one or sometimes two lines and are not big as you can see in the example.
Inline functions can increase the code size of your application and add stress to the instruction cache. Some debuggers have difficulty showing the thread of execution for inline functions. A function call itself can limit the compiler's ability to optimize register usage in the calling function.
Answer. An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.
There are two kinds of memory usage that inline functions will affect: code size — in general, inlining code will increase how much memory is used to load your program. This is because there will be multiple copies of the generated code scattered around your program.
Limitations of Inline FunctionsInline functions do not work if the body of the function contains any sort of looping or iteration. Inline functions do not support the use of switch or goto statements. C++ Inline functions cannot work if the function defined is recursive in nature.
I strongly suspect you're comparing apples to oranges.
Did you compiler with exactly the same compiler, the same compile flags, and making an application with the exact same functionality?
If so, disassemble the executable, and see what the extra code is.
My guess is that it's some one-off library code used to support C++ features that were previously unused.
But as always, don't guess, measure.
You've got a single data point. That doesn't tell you much. We could be looking at a 350% increase in file size in all cases, or we could be looking at a fixed 16kb overhead. You need to find out which it is. So get some more data points. Extend your application. Make it open ten windows instead of one, or otherwise add extra functionality. is "your" version three times as big in that case too? Or is it 16kb larger? Or somewhere in between? Get some more data points, and you'll be able to see how the file size scales.
But most likely, you're worrying over nothing, for several reasons:
The size difference is more likely to be due to the libraries which are pulled in for C++, rather than in your C equivalent there is less library overhead.
If all your wrapper code follows the above, then very little to none in terms of bloat.
Looks to me that your solution is a good worth while way of implementing the wrapper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With