On Thu, Oct 20, 2022 at 5:46 AM Slawomir Pryczek <slawek1...@gmail.com> wrote: > > Hi Guys, writing a quick K/V caching system and have a performance related > question. > > Will be operating on []byte, for the system to be thread safe we need to > create a copy of data before each SET so we're sure that the slice which gets > added to pool can't be modified. This shouldn't be problematic, but there's a > problem with GET. > > For the system to be thread-safe we need to isolate the returned slice from > the data pool so if we do, eg. x := Get("key_abc") we won't create issues by > later doing x[1]='a'. So we'll need to create a copy of whole key for each > GET. We will have very few SETs but millions of GETs. So is it possible for > the slice to be not-mutable like strings are or you can suggest some other > approach?
What if you simply return a string? If the caller must not modify the returned data, a string is more or less the same as a []byte. Ian -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVGy8wL7%2B5%3DiY5NWQsWsMbMGXNDsiUdmL3LFZSNnW1wmw%40mail.gmail.com.