FAQ
Hello!
This is my code in which i create a buffer and receive data in it.
in my code i allocate the buffer in every loop , and while go is a garbage
collector language so i don't need to destruct it.
my question is : is there a better solution to create the buffer with a
better consumption of memory ,
or should i destruct it every time ??


for {

         buffer1 := make([]byte,512)
         client.ReadClient(buffer1)
         str:=str2+string(buffer1)

         for {
                                 posSTX := strings.Index(str, string(0x02))
         posETX := strings.Index(str, string(0x03))
         if(posSTX==-1 || posETX==-1) {
return
}

if (strings.LastIndex(str, string(0x02)) != posSTX ||
strings.LastIndex(str, string(0x03)) != posETX) {

str1:=str[posSTX+1:posETX]
str2=str[posETX+1:]
str=str2

}else {
     Log("MsgR: ",str[posSTX+1:posETX])
     str2=""
}

if str2=="" || strings.Index(str2,string(0x03))==-1 {break}
     }
}

--
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

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 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