Freeing memory allocated at C function

2012-03-23 Thread Pedro Lacerda
I'm using some C functions like these: char *str = allocateNewString(); And this: Object *obj = constructObject(); // etc freeObject(obj); Do I need to free the memory in both cases? Can I someway register them on GC?

Re: Freeing memory allocated at C function

2012-03-23 Thread Pedro Lacerda
On Fri, Mar 23, 2012 at 3:43 AM, Ali Çehreli acehr...@yahoo.com wrote: You can register on GC if you wrap the resources in a class. Then the class object's destructor would call the clean up code. The problem is, it is undeterministic when the destructor will be called, or will it be called

Converting C .h Files to D Modules

2012-03-20 Thread Pedro Lacerda
Hi all, How to convert the following struct to D? typedef struct S { int type; void *obj; } S; I didn't found anything at http://dlang.org/htomodule.html.

Re: Converting C .h Files to D Modules

2012-03-20 Thread Pedro Lacerda
Ouch, void* is the same in both languages, sorry. I addressed a new problem: typedef struct SomeFunctions { void *(*funcA)(char*, size_t); void *(*funcB)(void); } SomeFunctions; How do I convert that functions references into an D struct? On Tue, Mar 20, 2012 at 3:01 PM, Pedro Lacerda

SocketStream exceptions and disconnect handling

2012-03-07 Thread Pedro Lacerda
(Error while writing); } But that's impossible because isAlive doesn't exists for SocketStream and I can't get the underlying socket object. Is that something missing or should I handle it differently? Pedro Lacerda

Re: SocketStream exceptions and disconnect handling

2012-03-07 Thread Pedro Lacerda
My english is bugged, I mean handle reconnections transparently. Sorry. Pedro Lacerda 2012/3/7 Pedro Lacerda pslace...@gmail.com Hi all, I'm trying to handle disconnections transparently on SocketStream. I thought something like this: void send(ubyte[] buffer) in { assert(buffer.length

Re: Redis client

2012-03-05 Thread Pedro Lacerda
Dmitry, very thanks for the reply! I'm going to make a nice API and acceptance testing using some Redis tutorial. With it working well do you think that worth make project marketing considering the overall code quality? Looking the sources pedantically what's wrong? Pedro Lacerda 2012/3/5

Redis client

2012-03-04 Thread Pedro Lacerda
that implement the protocol as free functions isn't a bad option because D offers this imperative style and the protocol is so small that doesn't need more a structured approach. Tell me this is wrong! thanks from a newbie :-) Pedro Lacerda

Is empty array null?

2012-02-27 Thread Pedro Lacerda
The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I missing? Pedro Lacerda

Re: Is empty array null?

2012-02-27 Thread Pedro Lacerda
Ouch, I just found http://d.puremagic.com/issues/show_bug.cgi?id=3889 So how would I differ from an empty array and a null value? Pedro Lacerda 2012/2/27 Pedro Lacerda pslace...@gmail.com The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I

Re: Is empty array null?

2012-02-27 Thread Pedro Lacerda
on another place? Pedro Lacerda 2012/2/27 bearophile bearophileh...@lycos.com Jonathan M Davis: Arrays treat null kind of funny. Seen with the knowledge of today, the D confusion between pointers and dynamic arrays was a design mistake. Recently a bit of this mess was fixed, now this is a syntax

Re: Templated aliases name in compilation error output

2012-02-13 Thread Pedro Lacerda
Would be bad or hard dmd keep those information, and outputs like gcc aka? Pedro Lacerda 2012/2/12 Jonathan M Davis jmdavisp...@gmx.com On Sunday, February 12, 2012 13:00:16 Trass3r wrote: dmd simply doesn't keep those information about aliases. Exactly. - Jonathan M Davis

Chatting with a server

2012-02-13 Thread Pedro Lacerda
? Pedro Lacerda

Templated aliases name in compilation error output

2012-02-11 Thread Pedro Lacerda
(typeid(mb)); } is: bla.__Bulk!(__Bulk!(byte)).__Bulk Despite in runtime I accept don't see aliases name, if it is needed for accomplish speed. What are your opinions about these erros output? Pedro Lacerda

Re: D at work

2012-02-09 Thread Pedro Lacerda
DVM is great for this: https://bitbucket.org/doob/dvm DVM sounds well, thanks! As for use cases, command line is a good bet. I suggest starting with something that has a clear scope and isn't chosen based on a marketing feature. For example if you're going to build a server of some sort

Re: Arrays - Inserting and moving data

2012-02-09 Thread Pedro Lacerda
I __believe__ that insertInPlace doesn't shift the elements, but use an appender allocating another array instead. Maybe this function do what you want. int[] arr = [0,1,2,3,4,5,6,7,8,9]; void maybe(T)(T[] arr, size_t pos, T value) { size_t i; for (i = arr.length - 1; i

Re: Using the Variant (Setting it's memory location)

2012-02-08 Thread Pedro Lacerda
for ulong e byte buffer.length = a.sizeof + b.sizeof; *cast(ulong *)buffer[offset] = a; // store value offset += a.sizeof;// increment offset *cast(byte *)buffer[offset] = b; offset += b.sizeof; Pedro Lacerda 2012/2/8 Era Scarecrow rtcv...@yahoo.com On Tuesday, 7

Event library

2012-02-08 Thread Pedro Lacerda
Hi all, I'm trying to do some evented programming and found libev at Deimos. I just want to auto loop = ev_default_loop(0); However I have no idea how to compile it. thanks, Pedro Lacerda

Re: Event library

2012-02-08 Thread Pedro Lacerda
Oh thanks, man. Pedro Lacerda 2012/2/8 bheads bhe...@barracuda.com On Wed, 08 Feb 2012 14:46:06 -0200, Pedro Lacerda wrote: You need to set the right libev version, and link with libev dmd main.d deimos/ev.d -Ipath to deimos -L-lev -version=LIBEV4

Re: Conversion to output ranges

2012-02-07 Thread Pedro Lacerda
Maybe std.outbuffer... auto buffer = new OutBuffer(); int a = 42; buffer.write(a); byte[] bytes = cast(byte[]) buffer.toBytes(); ubyte[] ubytes = buffer.toBytes(); Pedro Lacerda 2012/2/7 Mafi m...@example.org Hi, does anybody know how to bring std.conv.to

Re: Using the Variant (Setting it's memory location)

2012-02-07 Thread Pedro Lacerda
._bytes)); Pedro Lacerda 2012/2/7 Jesse Phillips jessekphillip...@gmail.com On Tuesday, 7 February 2012 at 00:39:00 UTC, Era Scarecrow wrote: Unfortunately I'd need to reference a buffer for the known structured types. Variant seems far more useful for making an interpreted language, than for my