From: nobuyoshi nakada Date: 2005-07-08T13:41:39+09:00 Subject: Re: Questions about GC, memory management and C extensions Hi, At Fri, 8 Jul 2005 09:43:19 +0900, Zed A. Shaw wrote in [ruby-talk:147507]: > 5. Many C libraries (like libevent) allocate their own memory for > structures and initialize in one shot, but the Data_Wrap_Object macros > and other functions seem to require pre-existing memory. This leads to > a contradiction where I must allocate the libevent structure in my > _alloc method, but initialize it in my _initialize method which I can't > do since allocation and initialization are done in one call. Is there a > way to create, initialize, and attach C library structures inside the > _initialize method only? Leave DATA_PTR NULL in alloc_func, and allocate new structure in #initalize. You'll have to check first if it is valid, in each instance methods. -- Nobu Nakada