copy


Description:

[ CCode ( cname = "memcpy" ) ]
public void* copy (void* dest, void* src, size_t n)

Copies count characters from the object pointed to by src to the object pointed to by dest.

If the objects overlap, the behavior is undefined.

Example: Copy bytes from src to dest:

public static int main (string[] args) {
char[] data = {'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\0'};

// Copy the data into a typeless buffer:
// Do not copy arrays / classes / etc when you do not know what you are doing.
// You may break your ref counters / lose array length information / etc
void* copy = try_malloc (sizeof (char)*data.length);
Memory.copy (copy, data, sizeof (char)*data.length);
print ("%s\n", (string) copy);
free (copy);

return 0;
}

valac --pkg glib-2.0 GLib.Memory.copy.vala

Parameters:

dest

pointer to the memory location to copy to

src

pointer to the memory location to copy from

n

number of bytes to copy * @return dest

Returns:

dest


Namespace: GLib.Memory
Package: glib-2.0