[Vala] disable free at block end
- From: MohanR <mohan43u gmail com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] disable free at block end
- Date: Thu, 10 Mar 2016 23:34:53 +0530
Hi,
May be a i'm wrong, but here is my issue,
namespace test {
struct Remote {
uint16 id;
uint32 ip;
}
class SocketReader: Object {
Socket socket;
Array<Remote*> remotes;
public SocketReader(Socket socket) {
this.socket = socket;
this.remotes = new Array<Remote*>();
}
public read() {
int8[] buffer = new int8[sizeof(Remote)];
while(socket.receive(buffer,
sizeof(Remote)) > 0) {
Remote* remote = Memory.dup(buffer,
sizeof(Remote));
this.remotes.append_val(remote);
}
}
}
}
when read() goes out-of-scope, "buffer" gets freed, So I have to
make a dup of that memory to store it in "remotes" array. But If I
have some way to tell vala not to free buffer, I dont need to dup the
buffer.
Am I doing this right? or any better way? All I need is to get the data
coming from the socket and use it as "Remote" struct. Need your
suggestions.
Thanks,
Mohan R
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]