From: MikkelFJ Date: 2003-03-09T20:20:50+09:00 Subject: Re: WIN32OLE: Passing an Array "pj" wrote in message news:127ce4a9.0303081536.6dd562eb@posting.google.com... > I am a clueless newbie in Ruby, knowing nearly less than nothing, but > arrays in COM (ie, OLE, ie, ActiveX, whichever name of the week you > like) are often passed as type SAFEARRAY. This is a structure holding > a dynamically allocated array (a traditional array of consecutive > bytes), but, and this is important, it is allocated using a task > allocator. That is, you cannot make one from your heap manager, unless > your heap manager is cooperating with the task allocator. This is extremely poorly documented - I suspect the task allocator is no different from ordinary memory - except perhaps applying a standard for synchronizing allocation and deallocation in multiple threads (i.e. no magic transfer of memory between processs or something). I did implement my own safe array allocation in an optimized DB engine and returned the result to the outside world. It appeared to work fairly well. Also, you can implement you own allocator interface if you can be bothered, so it is not completely standardized - this was what made me conclude it would be safe to allocate my own memory as long is I keep ownership of it. > There is a caveat: there are rules about memory ownership across COM > calls. If you are the caller, and you pass the ARRAY as a top-level IN > parameter only, then you own the memory, and the callee isn't allowed > to change it, and in this case, I believe you can get away with it not > being allocated from the task allocator. Yes, you need to obey the tricky who owns what rules - you certainly have to make sure the original allocator deallocates when using non-standard allocators. It is very easy to get this wrong with all sorts of by reference flags and what not. Mikkel