Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* perform allocations in 4k chunks; as FreeBASIC only runs on x86, this
- * allows for (hopefully) efficent memory allocation since we're allocating
- * an entire page at once.
- */
- void FBSTRING::init_FBSTRING(void *str, int length);
- {
- int m;
- m = length / 4096;
- if((length % 4096) > 0)
- m++;
- size = m * 4096;
- data = ::malloc(size);
- len = length;
- ::memcpy(data, str, length);
- (char *) data[length] = 0;
- }
- void FBSTRING::fini_FBSTRING()
- {
- if(data) free(data);
- data = 0;
- len = 0;
- size = 0;
- }
- /* initialize an empty string */
- FBSTRING::FBSTRING()
- {
- data = 0;
- len = 0;
- size = 0;
- }
- /* initialize a string from a character array */
- FBSTRING::FBSTRING(const char *s)
- {
- data = 0;
- len = 0;
- size = 0;
- if(s == 0) return;
- int s_len = strlen(s);
- init_FBSTRING((void *) s, s_len);
- }
- /* initialize a string from a character array, with a given starting offset. */
- FBSTRING::FBSTRING(const char *s, const size_t l)
- {
- data = 0;
- len = 0;
- size = 0;
- if(s == 0) return;
- int s_len = strlen(s);
- if (s_len < (int) l) return;
- int m = s_len - (int) l;
- init_FBSTRING((void *) s + (void *) l, m);
- }
- /* initialize a string from a character array, with a given starting offset
- * plus max length */
- FBSTRING::FBSTRING(const char *s, const size_t l, const size_t x)
- {
- data = 0;
- len = 0;
- size = 0;
- if((s == 0) || (x == 0)) return;
- int s_len = strlen(s);
- if (s_len < (int) l) return;
- int m = s_len - (int) l;
- init_FBSTRING((void *) s + (void *) l, m < x ? m : x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement