Re:The ups of downs of porting 50k lines of C++ to Go
by whyever on Saturday March 07, 2015 @06:11AM
(#9161584)
How can you have a POD struct without pointers if one of your fields is a string?
[ Parent
| on HN ]
Re:The ups of downs of porting 50k lines of C++ to Go
by logicchains on Saturday March 07, 2015 @06:28AM
(#9161604)
Couldn't it be done with a fixed-size array of runes or bytes? It's definitely possible in C/C++.
Re:The ups of downs of porting 50k lines of C++ to Go
by z92 on Saturday March 07, 2015 @09:08AM
(#9161837)
Not without wasting a lot of space depending on the difference between average size of string vs maximum size of string.
Re:The ups of downs of porting 50k lines of C++ to Go
by logicchains on Saturday March 07, 2015 @07:28PM
(#9163811)
We generally know the maximum string sizes for each property, and they're pretty small, so this wouldn't have been a problem.
Re:The ups of downs of porting 50k lines of C++ to Go
by a8da6b0c91d on Saturday March 07, 2015 @09:36AM
(#9161878)
You can use a string class like the one in Folly that decays from a fixed array to heap allocated space if the string gets too long.
Re:The ups of downs of porting 50k lines of C++ to Go
by masklinn on Saturday March 07, 2015 @09:08AM
(#9161838)
I believe it's also possible to use variable-size arrays in C or C++ (and end up with a variable-size struct).
Go does allow fixed size arrays in structs, and they're inline in the struct, so `struct { foo [8]uint }` is 32 bytes, whereas `struct { foo []uint }` is 12 bytes and `struct { foo string }` is 8.