New topic: Need Help With Memblock String Class
<http://forums.realsoftware.com/viewtopic.php?t=31467> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message x11joex11 Post subject: Need Help With Memblock String ClassPosted: Tue Dec 08, 2009 12:52 am Joined: Thu Oct 12, 2006 7:21 am Posts: 330 Location: California Hi there, A long time ago, I posted here and someone was nice enough to share with me a class called MemBlockString. It's a class that allows you to append to a string over and over again without taking a lot of memory up. For example, if you created a string and said string=string+"hey" and kept doing this over and over again it would eventually slow down to a crawl, but with the memBlockString it would keep going at top speed because it appends using memory instead of an algorithm to figure out where it's supposed to go. With this in mind let me explain the class below and then share my problem. The memBlockString class '3' methods. -appendString(s as string) -constructor -getString() as string it has '5' properties -bufferSize as integer -length as integer -mb as memoryBlock -tempMB as memoryblock -totalLength as integer The appendString function looks like the following. Code:#pragma disableBackgroundTasks dim l as integer l = len(s) mb.StringValue(length,l) = s length = length + l Exception//If we write of the end of the memoryBlock we need to replace it with a newer bigger one TotalLength = TotalLength+bufferSize mb.size = totalLength mb.StringValue(length,l) = s length = length + l The Constructor looks like... Code://This is a class to use a memoryBlock as a temporary buffer //while creating long strings by appending to already existing //strings. It can be a lot quicker than s = s + "more text" if //you have very long strings //This is both the size of the original memoryBlock //but also how much it increases by each time if needed BufferSize = 100000000 //bigger than really needed and probably big enough for what needs to be done~ mb = newMemoryBlock(BufferSize) TotalLength = BufferSize getString looks like... Code:#pragma disableBackgroundTasks return mb.stringValue(0,length) That is the entire class, pretty simple, but somewhere in here is the error I'm having. This memBlockString class 'DOES' work and very well I've used it for years until now. I was creating a database adding with tons of queries of names and at one point the names included uni64 code type characters, like special symbols in the french and spanish language etc or japanese characters and what not. Now sqLITE should be able to handle those as inputs so I was confused for a while on why I was getting an error but I've narrowed it down to memBlockString not returning the entire data of the 'string' correctly. For some reason when it's appending the string with data that has the special unicode characters in it it seems to screw up and return the incorrect amount of data. I'm not sure why, but I suspect unicode characters take up more bytes of information and this is affecting how it works, but I'm not sure how to fix it. Any help would be appreciative. Basically what I need help in a nutshell is how to make MemBlockString class support unicode type characters and still be able to appendStrings correctly. _________________ -=Domain Finder=- domain name finder Top x11joex11 Post subject: Re: Need Help With Memblock String ClassPosted: Tue Dec 08, 2009 12:59 am Joined: Thu Oct 12, 2006 7:21 am Posts: 330 Location: California LOL, this is kind of funny but I think I just fixed it, and it was only '1' line of code. In the append string function I changed I=len(s) to I=lenB(s), it appears in this case I needed to get the length in bytes instead of just characters since unicode characters messed things up. Now it works correctly =). _________________ -=Domain Finder=- domain name finder Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
