[webkit-dev] WebKit memory management?

Mark Rowe mrowe at apple.com
Tue Jun 3 22:04:46 PDT 2008

On 03/06/2008, at 21:13, Paul Pedriana wrote:

> Thanks for the info. IMHO, tcmalloc is not appropriate for console,
> embedded, and mobile platforms. It trades space for speed, and that's
> the opposite of what you want outside the desktop. This is why the  
> Nokia
> S60 people replaced tcmalloc, for example.

As far as I can tell, Nokia's S60 port predates the adoption of  
tcmalloc by WebKit.  The code in their latest svn.webkit.org source  
tree contains a variant of dlmalloc that was used up until Safari 2.0,  
though I have not checked to see whether it is compiled in to their  
build.  That said, it is obvious that the space vs. speed tradeoffs  
differ between devices, and that flexibility in the memory allocator  
used is desirable.

> Unfortunately, overriding operator new and delete does not do the  
> right
> thing. These operators are application-global functions and when you
> redirect them for one library you are thus redirecting them for the
> entire rest of the app. Needless to say, that is a bad thing. In  
> console
> and embedded development, as I note in the aforementioned paper, it is
> typically verboten for a library to use operator new/delete.

On the platforms with which I am familiar, the implementation that I  
linked to has no effect outside of the library in which it is  
defined.  I've not worked with consoles or embedded devices so the  
toolchain and environment may differ there, but I would be a little  
surprised to see an inline function that is implemented in a header  
become visible to an object file that did not include the header.

> Neither will you see professional commercial software do this.

> It's also a problem to have any calls to system malloc at all,  
> because often on
> these platforms there is little or no memory available, as the
> application has taken it all to distribute to private heaps as per  
> their
> budget.

The direct calls are few and far between.  They can easily be  
evaluated to determine which, if any, have a legitimate need to call  
the system allocator and the remainder updated to use "fastMalloc" /  
"fastFree".  I'd gladly review a patch that moves in this direction.

> One simple and effective way to solve this problem is to provide a
> memory config header file which defines macros or templates which
> replace new/delete, malloc/free. Instead of calling global new, WC_NEW
> (e.g.) is called instead.

How does this differ from FastMalloc.h and "fastMalloc" / "fastFree"  
that I described in my previous email, other than addressing the  
perceived problem with "operator new" / "operator delete"?

> This is how commercial-quality software is done

Kind regards,

Mark Rowe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2413 bytes
Desc: not available
Url : http://lists.webkit.org/pipermail/webkit-dev/attachments/20080603/8b7cfbf3/attachment.p7s 

More information about the webkit-dev mailing list