n00b questions

43 views
Skip to first unread message

DIY DSP

unread,
Apr 12, 2012, 3:48:07 PM4/12/12
to Logog
Hi, sorry if I offend anyone with my silliness, but why does logog use
its own string and allocation classes instead of using string::string,
and new/delete ?

Thank you,
DIY DSP

John Byrd

unread,
Apr 14, 2012, 6:03:01 AM4/14/12
to lo...@googlegroups.com
That's not a silly question at all. The logog library spends a lot of
time moving strings as parameters between classes. The default
std::string implementation on most machines tries to minimize memory
usage, and as such it reallocates the memory buffer for a string
whenever a string is appended to. Additionally, copying a std::string
is a deep copy operation which requires allocating memory. For DSP
applications, allocating memory is usually an expensive operation and
so we try to avoid it.

Originally I was using std::string in logog but std::string was just
spending too much time allocating and deallocating memory, so I rolled
my own semi-compatible class. It's not a drop-in replacement -- it
requires the caller to keep track of whether the memory pointed to by
the logog::string is const (non-freeable) or allocated in the heap.

C++11's support of move constructors may make the logog::string
implementation unnecessary, but that will be a few years off yet.

jwb

> --
> You received this message because you are subscribed to the Google Groups "Logog" group.
> To post to this group, send email to lo...@googlegroups.com.
> To unsubscribe from this group, send email to logog+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/logog?hl=en.
>

--
---

John Byrd
Gigantic Software
2102 Business Center Drive
Suite 210-D
Irvine, CA   92612-1001
http://www.giganticsoftware.com
T: (949) 892-3526 F: (206) 309-0850

Reply all
Reply to author
Forward
0 new messages