On 2013/01/16 14:24, Max Kellermann <m...@duempel.org> wrote:
>  class Path : private std::string { ... };

I did a few experiments here to judge the overhead of this.  I started
with a "char*" attribute instead of deriving from std::string, to
avoid the overhead of duplicating the g_convert() result again for
std::string construction.

The preliminary patch is in my branch "path":
 http://git.musicpd.org/cgit/cirrus/mpd.git/log/?h=path

My goal was to avoid overhead, but I failed, while at the same time
learning something about C++ again.

First thing I learned: free() is better than g_free().  The compiler
seems to "know" about the nature of free(), and when the compiler
figures out that the parameter is NULL, it will not generate a call to
free(), because the compiler knows it's a no-op anyway.  The compiler
does not know about g_free().  (Tested with clang)

Second: structs/classes can be passed/returned in a simple register
UNLESS the class has a non-trivial destructor or a non-trivial copy
constructor.  My patch explicitly "deletes" the copy constructor, but
the destructor must be non-trivial because it must call free().

(The copy constructor limitation doesn't seem to make sense in the
presence of a trivial move constructor, could be a clang bug)

Unfortunately, this means that a Path instance can never be passed in
a register, it must always go the round-trip to memory and back.  This
adds overhead.  Admittedly not much, but useless, and enough to annoy
me.

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to