FAQ
Hi

In the recent post by Rob Pike, specifically in the garbage collection
section:
http://talks.golang.org/2012/splash.article#TOC_14.

I'm having trouble understanding this sectio:

*"As a more direct example, in Go it is easy and efficient to provide
second-order allocators, for instance an arena allocator that allocates a
large array of structs and links them together with a free list. Libraries
that repeatedly use many small structures like this can, with modest
prearrangement, generate no garbage yet be efficient and responsive."*
*
*
Can anyone give an example / explanation of this?

Thanks
Ryan

--

Search Discussions

  • Jan Mercl at Dec 5, 2012 at 11:52 am

    On Wed, Dec 5, 2012 at 12:46 PM, Ryan Slade wrote:
    "As a more direct example, in Go it is easy and efficient to provide second-order allocators, for instance an arena allocator that allocates a large array of structs and links them together with a free list. Libraries that repeatedly use many small structures like this can, with modest prearrangement, generate no garbage yet be efficient and responsive."

    Can anyone give an example / explanation of this?
    See for example: http://golang.org/src/pkg/regexp/exec.go#L91

    -j

    --
  • Ryan Slade at Dec 5, 2012 at 12:31 pm
    Thanks

    Surely you could do this in almost any GC language though? In what way does
    Go make this easier?

    My background is mostly C# where it's possible to pass references around,
    is this something that's not possible in Java for example?

    On Wednesday, 5 December 2012 11:51:46 UTC, Jan Mercl wrote:
    On Wed, Dec 5, 2012 at 12:46 PM, Ryan Slade wrote:
    "As a more direct example, in Go it is easy and efficient to provide
    second-order allocators, for instance an arena allocator that allocates a
    large array of structs and links them together with a free list. Libraries
    that repeatedly use many small structures like this can, with modest
    prearrangement, generate no garbage yet be efficient and responsive."
    Can anyone give an example / explanation of this?
    See for example: http://golang.org/src/pkg/regexp/exec.go#L91

    -j
    --
  • Jan Mercl at Dec 5, 2012 at 12:38 pm

    On Wed, Dec 5, 2012 at 1:31 PM, Ryan Slade wrote:
    Thanks

    Surely you could do this in almost any GC language though? In what way does
    Go make this easier? My background is mostly C# where it's possible to pass references around, is
    this something that's not possible in Java for example?
    For example, one cannot at all control where Java allocates a class
    instance. In Go, in the previously mentioned example, the instances of
    `*regexp.thread` are allocated in `machine.pool` slice and that can
    Java do as well. In other cases, or perhaps even in this one, some
    other `pool` can hold the entities instances directly, not only the
    pointers to them. This way it is possible in Go to explicitly manage,
    in reasonable cases, where "allocated" entities are stored. Once
    again, with e.g. Java that's not possible.

    -j

    --
  • ⚛ at Dec 5, 2012 at 6:44 pm

    On Wednesday, December 5, 2012 1:31:33 PM UTC+1, Ryan Slade wrote:

    Thanks

    Surely you could do this in almost any GC language though?
    You can do it in any GC language, but in GC languages like Java it most
    likely wouldn't deliver reduced memory consumption nor greater execution
    speed.

    In my opinion, the mentioned example
    http://golang.org/src/pkg/regexp/exec.go#L91 is close to what Rob meant in
    the article, but it isn't what he meant. He probably meant to allocate a
    linear array of structs and let the custom "2nd order" allocator return
    pointers to elements in the array. When the code is done with an element,
    the element is sent to the custom "2nd order" memory manager (M) which
    appends the element to a free list. When M is created it may pre-populate
    the free list, but this isn't strictly required.

    In what way does Go make this easier?
    In C# and Java it is impossible to get a pointer (type: *T) to any element
    of an array (type: [N]T or []T).

    My background is mostly C# where it's possible to pass references around,
    is this something that's not possible in Java for example?

    On Wednesday, 5 December 2012 11:51:46 UTC, Jan Mercl wrote:
    On Wed, Dec 5, 2012 at 12:46 PM, Ryan Slade wrote:
    "As a more direct example, in Go it is easy and efficient to provide
    second-order allocators, for instance an arena allocator that allocates a
    large array of structs and links them together with a free list. Libraries
    that repeatedly use many small structures like this can, with modest
    prearrangement, generate no garbage yet be efficient and responsive."
    Can anyone give an example / explanation of this?
    See for example: http://golang.org/src/pkg/regexp/exec.go#L91

    -j
    --
  • Paulo Pinto at Dec 5, 2012 at 11:53 pm

    On Dec 5, 7:44 pm, ⚛ wrote:
    On Wednesday, December 5, 2012 1:31:33 PM UTC+1, Ryan Slade wrote:
    ...>
    In what way does Go make this easier?
    In C# and Java it is impossible to get a pointer (type: *T) to any element
    of an array (type: [N]T or []T).
    Like this, http://msdn.microsoft.com/en-us/library/cx9s2sy4%28v=vs.100%29.aspx
    ?

    --
  • Si guy at Dec 6, 2012 at 12:42 am
    Slightly off-topic, but working in c# and go every day - the languages feel
    remarkably similar in that c# contains most of the features of go (GC,
    function pointers(delegates/anon funcs), type safety and unsafe,
    reflection, interfaces: c# uses a more java-like method than go). Go idioms
    are particularly useful in c# most of the time, obviously not relating to
    generics or channels.

    Sometimes I wonder if Hejlsberg and Pike are in cahoots.
    On Wednesday, December 5, 2012 11:35:42 AM UTC-8, Paulo Pinto wrote:
    On Dec 5, 7:44 pm, ⚛ wrote:
    On Wednesday, December 5, 2012 1:31:33 PM UTC+1, Ryan Slade wrote:
    ...>
    In what way does Go make this easier?
    In C# and Java it is impossible to get a pointer (type: *T) to any element
    of an array (type: [N]T or []T).
    Like this,
    http://msdn.microsoft.com/en-us/library/cx9s2sy4%28v=vs.100%29.aspx
    ?
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 5, '12 at 11:46a
activeDec 6, '12 at 12:42a
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase