return *(cast(T*)vPtr) and OutOfMemoryException

TSalm TSalm at free.fr
Sat Feb 14 08:34:48 PST 2009


Hello,

In the code below, why the first Stdout throws a Exception when the second  
doesn't ?

/*  -------- CODE --------   */
import tango.io.Stdout;


struct VoidPtr(T)
{
   void* vPtr;

   void value(T val)
   {
     vPtr = &val;
   }

   T value()
   {
     return *(cast(T*)vPtr);
   }
}


void main()
{
   VoidPtr!(char[][]) vPtr ;

   char[][]  arr = [ "hello" , "you" ];

   vPtr.value =  arr ;

   Stdout( vPtr.value ).newline; // <--  
[tango.core.Exception.OutOfMemoryException: Memory allocation failed

   Stdout( *(cast(char[][]*) vPtr.vPtr ) ); // <-- This works good
}

/*  ------ END CODE ------  */


Thanks in advance for your help,
TSalm


More information about the Digitalmars-d-learn mailing list