On 2013/01/16 14:14, Denis Krjuchkov <de...@crazydev.net> wrote: > 16.01.2013 19:00, Max Kellermann ??????????: > >First you map UTF-8 to filesystem path (e.g. via map_uri_fs()), which > >duplicates the string. Then for conversion to your path class (for > >passing to a system call), std::string duplicates the string again. > >Makes two allocations instead of one, even on sane operating systems. > > OK. This doubles the copying. But what if we don't adopt std::string > and use custom memory management? This would allow transfer of > ownership of allocated string from character conversion routine to > our wrapper. I think this still gives some protection because it > would be clearly noticeable if such string is going to be combined > with char* string which might have other encoding. Don't you agree?
Why custom memory management, when std::string already does all we need? Transfer of ownership is std::move(). But only if internal path names are already in std::string, which was my suggestion. But it's even easier; with my idea, you don't need to transfer ownership at all. Let some code do the talking: class Path : private std::string { ... }; (Base class is "private" so you can't accidently cast to a "normal" std::string.) Then you have a portability library which overloads some system calls: static inline FILE *fopen(const Path &path) { return fopen(path.c_str()); } No overhead here. On Windows, this function resolves to this instead: FILE *fopen(const Path &path) { SystemPath system_path(path); return fopen(system_path.c_str()); } Some overhead on Windows. Next step: #ifdef WIN32 class Path : private std::wstring { ... }; static inline FILE *fopen(const Path &path) { return _wfopen(system_path.c_str()); } #endif This eliminates the remaining overhead on Windows. ------------------------------------------------------------------------------ Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 _______________________________________________ Musicpd-dev-team mailing list Musicpd-dev-team@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team