Thanks Stephen, that's a lot of helpful info.  So in regards to
providing v8 with helpful information, what are the implications of
"cheating" with the memory hints?  I'm using libxml and there's no
good way to find out exactly how much memory was just allocated when a
node is created.  But the library does provide a method that gives the
*total* amount of memory allocated.

http://xmlsoft.org/html/libxml-xmlmemory.html#xmlMemUsed

So rather than trying to be surgical with the calls to AAoEAAM, I was
thinking of maintaining a variable with the total memory used.  And
everytime something is allocated or freed then I would decrement by
the previous value, and immediately increment by the new total memory
value.  Does anyone see problems with this level of "churn" on the
memory hints?

:Marco

On May 7, 3:40 am, Stephan Beal <[email protected]> wrote:
> On Thu, May 6, 2010 at 11:54 PM, Camilo Aguilar <[email protected]>wrote:
>
> > Thank you for your quick answers but what happens if I have a library like
> > libxml, gnutls, c-ares, libvirt, etc. They have theirs own internal memory
> > allocations and deallocations. Does this affect the v8 garbage collection
> > heuristics?
>
> Not directly, no. v8 cannot know how much memory libexpat, curses, etc.
> allocate for themselves, and the AdjustAmountOfExternalAllocatedMemory() API
> (try typing that 10 times quickly) is there so we can give v8 a hint about
> how much we've allocated. For bound C++ types i sometimes add a member,
> something like "memoryUsage()", which i can use for this purpose, but it is
> important that you pass the same relative value to AAoEAAM() when
> incrementing/decrementing the value, to avoid that the allocation hints end
> up out of sync.
>
> Unless v8 and all bound funcs/classes use the same allocator, there really
> is no in-language way of knowing how much memory is in use by each
> component. When importing other libs, which may in fact use their own
> allocators, the best we can do is guess and give v8 that number. Keep in
> mind that in C++ library authors can re-implement the 'new' operator, which
> means that (in theory, though not in practice) a library with 100 classes
> _could_ use 100 different allocation sources.
>
> That said, for "most" desktop purposes, it's not critical to make v8 aware
> of memory used by the internals of 3rd-party code.
>
> > I need to hack each library that I want to use through Javascript to add
> > AdjustAmountOfExternalAllocatedMemory in everyone of them?
>
> If you _need_ that feature, yes. In my experience, though, it's not
> critical.
>
> --
> ----- stephan bealhttp://wanderinghorse.net/home/stephan/
>
> --
> v8-users mailing list
> [email protected]http://groups.google.com/group/v8-users

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to