![]() |
Binary Q - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17) +---- Thread: Binary Q (/showthread.php?tid=1630) |
Binary Q - seraphelic - 20-03-2008 I was told a string is 10 bytes + string length. Why then, is a string of 20 chars only 20 bytes??? EDIT: does anyone have AIM or MSN I could bug? I don think these questions are worth a whole post >.> EDIT2: I think the whole string = string length + 10 is bullshit. I dont run into any problems if I only presume the string = string length. Re: Binary Q - Spodi - 20-03-2008 seraphelic Wrote:I was told a string is 10 bytes + string length. Why then, is a string of 20 chars only 20 bytes??? Because an array of chars (not a string of chars, theres no such thing) is not the same thing as a string. A string has a header and a 2-character terminator along with probably some other information to define it. Although you could easily write your own class to support char arrays for strings if the memory was so critical, it'd probably be slower in the end. .... Test time! I'll edit with the results here in a couple minutes. Edit: Code: class Program Simple CharString class that supports string appending and reading. Results: Code: Write CharString: 7 The writing was a bit unexpected, but the reading is about how you'd expect it. But keep in mind that, even though this is C#, the implementation is probably going to be close language-by-language. The overhead of the write is probably a combination of the string being reconstructed every append instead of cached like I did (since heavy string writes often should use a class like .NET's StringBuilder) and overhead from validation checks. I added in some threading safety to be a little more fair. ![]() Point being although you can write a faster string class for a specific case, if you need more speed or memory, you shouldn't be using strings or are approaching things the wrong way. ![]() Re: Binary Q - seraphelic - 21-03-2008 Look, while I am intelligent enough to comprehend what you just said, there's no point in trying to when my question was so simple. Maybe I'll ask the audience one more time. Let me see if I have this right: Dim first As String Dim second As String * 10 first = "Lorem Ipsum" '11 chars SO first is 32 bytes (10 + 2(11))? and second is 10 bytes? Lemme know if I know my stuff yet. |