caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2002-10-22 15:01 climb
  2002-10-22 16:30 ` [Caml-list] Re: char array vs. string Chris Hecker
  0 siblings, 1 reply; 2+ messages in thread
From: climb @ 2002-10-22 15:01 UTC (permalink / raw)
  To: caml-list

Dear caml-list
 i want to build a function  f: char array -> string     which just make a char array into a string. But i dont want to do like this
let f ary=
    let str = String.create(Array.length ary) in
    for i=0 to (Array.length ary)-1 do
       str.[i]<- ary.(i)
    done ;
    str;;

since if do like this, i have to make a new string of extra memory, what i want to generate is a string that share the same memory with the char array.
The reason is that i should deal with  'a array , however when it is a char array, i want to seen it as a string in order to do some regular matching which can only take on strings. But my problem is that the char arrays are very long(1M each or longer) ,so it is expensive to make a string copy of it. 
In o'relly 's book, it says Character strings can be considered a special case of vectors of characters.
Then what shall i do ?   or my function above is efficient enough ? or i cannt do the shareing because as the book says that one char in string is a byte .
?


Best regards
            
              Yours
                         climb
                         onlyclimb@163.com
                         2002-10-22

 




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Caml-list] Re: char array vs. string
  2002-10-22 15:01 climb
@ 2002-10-22 16:30 ` Chris Hecker
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Hecker @ 2002-10-22 16:30 UTC (permalink / raw)
  To: climb, caml-list


>  i want to build a function  f: char array -> string     which just make 
> a char array into a string. But i dont want to do like this
>let f ary=

I think that's all you can do.  A char array is a proper caml array of 
chars, and chars are stored as ints outside of strings.  So, 
[|'a';'b';'c';'d'|] is 4 words long, while "abcd" is only 4 bytes long.

Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-22 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-22 15:01 climb
2002-10-22 16:30 ` [Caml-list] Re: char array vs. string Chris Hecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).