Re: Reducing unncessary string copying



2012/2/20, Enrico Weigelt <weigelt metux de>:
> * André Gillibert <metaentropy gmail com> schrieb:
>
>> This adds some level of indirection to access the data bytes, and some
>> space overhead.
>> For example, the string "hello" is 6 bytes long (including the zero
>> terminator), with GLIBC's malloc, it may occupy 8 bytes (or maybe 16
>> bytes).
>> With your implementation, it would occupy twice as much memory.
>
> No. With my approach, strings aren't a single bit longer.
> References to them require one more byte. (well, maybe more due padding).
> On certain platforms/architectures (eg. 64bit), we maybe even could put
> that single bit directly into the pointer (using the MSB if we can be
> sure the upper half is never used).
>
Ok. If you pass around this structure as a value.
This indirectly increases the size of a data structure such as:
struct MyClass
{
  GCStr some_string;
  GCStr another_string;
} ;

And there are a lot of them...

>> Moreover, the binary code using strings would be larger of a few bytes
>> too.
>
> No. Plain access is not is not a single bit larger, ist just an offset.
>

Copying a pointer (e.g. 8 bytes on 64 bits platform) requires less
code than copying a pointer and a char (which may occupy 16 bytes for
alignment purposes).

-- 
André Gillibert


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]