Re: [Vala] How to get a const substring without copying?
- From: Thijs Vermeir <thijsvermeir gmail com>
- To: PCMan <pcman tw gmail com>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] How to get a const substring without copying?
- Date: Sun, 6 Nov 2011 16:16:27 +0100
On Sun, Nov 6, 2011 at 3:44 PM, PCMan <pcman tw gmail com> wrote:
Hello,
It's me again.
In C language, sometimes we do this:
char* uri = "ftp://140.112.172.1";
char* ip = str + 6; // get the IP part of the string without copying.
With vala, either string.substring() or string[start:end] needs copying.
Is it possible to do the above in vala? In trivial cases this causes no
difference.
However, for more performance critical code, this can reduce many
unnecessary malloc/free.
Is this possible in Vala anyways?
I cannot find any clues in the tutorials and the docs.
Yes,
this should do it:
public static void main (string[] args)
{
string hello_world="hello world";
unowned string world=(string) ((uint8 *)hello_world + 6);
print ("%s\n", world);
}
Gr,
Thijs
Thanks
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]