On Mon, Nov 24, 2014 at 6:34 PM, Jason E. Aten <
j.e....@gmail.com> wrote:
>
> On Mon, Nov 24, 2014 at 3:48 PM, minux <
mi...@golang.org> wrote:
>>
>> If you want to do manual memory management, fine, write your own memory
>> allocator
>> or port existing ones using syscall.Mmap (VirtualAlloc on Windows). GC
>> won't ever scan
>> any objects allocated from that heap.
>
>
> I didn't realize that I could allocate Go structs on another heap if they
> contained other Go structs, slices, and strings. I assumed, perhaps
> incorrectly, that this would require a C++ style "placement new", but I
> wasn't aware of any such thing
As you know, Go does not have constructors, so there is no need for
placement new. syscall.Mmap will return a []byte. To convert that
into a pointer to some type T, write something like
p := (*T)(unsafe.Pointer(&b[0]))
> How does one tell the memory allocator to
> recursively use a specific heap for all recursive allocations?
You can't. You would have to manage that yourself, as in C.
>> But I don't think unsafe memory management primitives should ever be
>> introduced to the
>> Go runtime. There are much better ways than adding unsafe free primitive
>> to reduce GC
>> pauses times, and one of Go 1.5's goal is to reduce the pause time using
>> concurrent GC.
>
>
> I don't really understand the reservations. It is optional. If you don't
> need it, don't use it.
Off the top of my head:
* It constrains all future GC implementations.
* It makes the GC API more complex (the current GC API is about as
simple as possible, which is a good thing).
* It adds a rarely used code path to some of the most complex runtime
code.
* The current GC measures every bit that it uses; this new feature
would add a new feature that would need to be tracked in some way,
effectively causing the GC to slow down and/or use more memory for
something that would be rarely used.
Of course these problems would be inconsequential if the feature were
really needed, but given the future GC plans I don't think it is.
> For some programs, pausing for 1500 msec is a real
> problem.
Yes. Hence the plan, described at
http://golang.org/s/go14gc, to make
GC pauses very very short in future releases.
Ian