FAQ
You have lots of other options. One is to allocate a buffer outside the
loop for use in small messages, and allocate per-message for big messages.

msgbuf := make([]byte, 1024)

for ;; {
     msgsize = ....
     var buf []byte
     if msgsize > 1024 {
         buf = make([]byte, msgsize)
     } else {
         buf = msgbuf[:msgsize]
     }
     client.ReadClient(buf)
}

You could get arbitrarily more complicated if you care. You probably
shouldn't.
On Wednesday, April 16, 2014 12:58:07 AM UTC-7, farah wrote:

Why can't you allocate buffer1 outside the outer for loop?
the buffer should be allocated and empty every time the server
receives a message because the buffer will recover the message received.
and i can't allocate a buffer with a huge capacity , it's a loss of
memory and also i can't predict the size of the buffer.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 8 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 15, '14 at 11:23a
activeApr 18, '14 at 10:20a
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase