You are still avoiding answering the one simple question that would explain
perfectly well, without any room for misunderstanding, what you are
proposing. I would also like to point out again that I am not arguing in
favor or against the C++ or the Java way. I am simply trying to get you to
answer the question which of the two you are proposing.

On Fri, Jul 1, 2016 at 10:59 PM, Andrew Mezoni <andrew.mez...@gmail.com>
wrote:

> >> That there is an indirection in the struct doesn't mean that a function
> doesn't need to know the size of the memory it is allocating for a bucket.
>
> Your judgement are now incorrect.
> Obtaining the size of the of the type is not so hard at runtime.
> It always known from `rtype`
>
> This is how map allocates buckets.
> It creates an array of the type `t.bucket`.
> Where `t` is `mapType` and  the `bucket` is a field in this type which
> specifies the the better type of storing buckets.
>
> if h.buckets == nil {
>       h.buckets = newarray(t.bucket, 1)
> }
>
>
> How new array know the size?
>
> This is easiest question in the world.
>
> Answer is: From a given type.
>
>
> // implementation of make builtin for slicesfunc newarray(typ *_type, n 
> uintptr) unsafe.Pointer {
>       flags := uint32(0)
>       if typ.kind&kindNoPointers != 0 {
>               flags |= flagNoScan
>       }
>       if int(n) < 0 || (typ.size > 0 && n > _MaxMem/uintptr(typ.size)) {
>               panic("runtime: allocation size out of range")
>       }
>       return mallocgc(uintptr(typ.size)*n, typ, flags)
> }
>
>
> Look how passed the `key` into the `map` method `get` (mapaccess).
> It passed as the unsafe.Pointer.
>
> func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
>
>
> P.S.
>
>
> The `map` is very well oprimized in Go language (it has more than one method 
> for different groups of types).
>
> But this does not means that the code generated for use "a single method for 
> every groups of types" approach would be much more slower.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to