guile-user
[Top][All Lists]
Advanced

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

Re: null terminated strings


From: Per Bothner
Subject: Re: null terminated strings
Date: Mon, 19 Jan 2004 10:46:35 -0800
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6) Gecko/20040113

Ken Anderson wrote:

>    In Java, which does copy-on-write

String (including substrings) are immutable, so they cannot be written.
The implementation of the StringBuffer class does do copy-on-write, but
that doesn't affect substrings.

i often find myself  carefully copying the substrings so they don't share 
structure.

Why?  The only reason I can think of is garbage collection:  A shared
substring prevents the base from being collected.

This is because of things like:
- i don't know how long the underlying string (char array actuall) is.

So?

Java only has one kind of string, which is fairly heavy weight.  For example, the string 
"" takes 36 bytes:

(describe "")
 is an instance of java.lang.String

  // from java.lang.String
  value: address@hidden
  offset: 0
  count: 0
  hash: 0

This depends on the implementation, and the version of the
implementation.

GCJ uses for "":
  object header (4 bytes on 32-but systems)
  private Object data; /* points to itself in this case */
  private int boffset; /* offset of first char within data */
  int count; /* number of character */
  private int cachedHashCode;
  /* chars follow if data==this */
(The data and boffset fields are only accessed by native C++ code.)

Total 20 bytes.
--
        --Per Bothner
address@hidden   http://per.bothner.com/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]