Re: [go-nuts] zero value for generic types?

2022-04-20 Thread Arthur Comte
Actually, even with proper error handling, I still need to return a value. In some functions I can just return a variable that was defined in the function, but that is not always available. In those cases, the only solution I've found is to use `*new(E)`, which seems plain terrible. Is there an alt

[go-nuts] zero value for generic types?

2022-04-20 Thread Arthur Comte
Hi! I was trying the following code, but it does not compile. How can I check if a generic value is its zero value. More broadly, can you explain where this issue comes from? ```go type MemoryRepository[E identifiable.Identifiable] struct { elements []E } func (repo MemoryRepository[E]) Find(I

[go-nuts] Why does Go not have intrinsic functions?

2022-04-07 Thread Arthur Comte
Intrinsic functions (functions that compile down to one hardware instruction) are common in (relatively) low-level languages. Go even supports embed ASM (though a weird flavour of it) Can someone explain why we do not have an intrinsic function package? This seems like it would greatly ease the

[go-nuts] Re: Go can't alloc custom objects from byte slice's memory address?

2016-07-09 Thread Arthur
finally, I find the reason: the allocated objects can't have reference to other objects, because GC don't know those reference and would recycle them. after GC, we'll have dangling pointer and may meet strange behavior. 在 2016年7月9日星期六 UTC+8下午1:11:49,Arthur写道: > > my p

[go-nuts] Re: Go can't alloc custom objects from byte slice's memory address?

2016-07-08 Thread Arthur
I've tested []myObjType instead []byte, it works. but I have many different kinds of object, so if a build []T for every type of object, the code is ugly. I'm sure my code don't access memory out of range, it's something related to the conversions. 在 2016年7月9日星期六 UTC+8下午1:51:46,Tamás Gulácsi写道:

[go-nuts] Re: Go can't alloc custom objects from byte slice's memory address?

2016-07-08 Thread Arthur
:05,Chad写道: > > Create an array instead. But with the progress of the GC algorithm... not > sure you should encounter such GC pressure. > > On Saturday, July 9, 2016 at 7:11:49 AM UTC+2, Arthur wrote: >> >> my program allocates many different kinds of small object,

[go-nuts] Go can't alloc custom objects from byte slice's memory address?

2016-07-08 Thread Arthur
my program allocates many different kinds of small object, and that gives GC a lot pressure. so I wan't to make a big slice and split object from it manually. block = make([]byte, 30*1024) myObj := (*myObjType)(unsafe.Pointer(&block[offset])) I write a simple allocator to do it, but I meet stran