public void Dispose()
        {
            if (constantBuffers != null)
            {
                Marshal.FreeHGlobal((IntPtr)constantBuffers);
                constantBuffers = null;
            }

            if (textures != null)
            {
                Marshal.FreeHGlobal((IntPtr)textures);
                textures = null;
            }

            if (samplers != null)
            {
                Marshal.FreeHGlobal((IntPtr)samplers);
                samplers = null;
            }

            if (randomAccessBuffers != null)
            {
                Marshal.FreeHGlobal((IntPtr)randomAccessBuffers);
                randomAccessBuffers = null;
            }
        }
        public ShaderEffectDesc_NativeInterop(ref ShaderEffectDesc desc)
        {
            // init defaults
            constantBufferCount     = 0;
            textureCount            = 0;
            samplersCount           = 0;
            randomAccessBufferCount = 0;
            constantBuffers         = null;
            textures            = null;
            samplers            = null;
            randomAccessBuffers = null;

            // allocate constant buffer heaps
            if (desc.constantBuffers != null)
            {
                constantBufferCount = desc.constantBuffers.Length;
                constantBuffers     = (ShaderEffectConstantBuffer_NativeInterop *)Marshal.AllocHGlobal(Marshal.SizeOf <ShaderEffectConstantBuffer_NativeInterop>() * constantBufferCount);
                for (int i = 0; i != constantBufferCount; ++i)
                {
                    constantBuffers[i] = new ShaderEffectConstantBuffer_NativeInterop(ref desc.constantBuffers[i]);
                }
            }

            // allocate texture heaps
            if (desc.textures != null)
            {
                textureCount = desc.textures.Length;
                textures     = (ShaderEffectTexture_NativeInterop *)Marshal.AllocHGlobal(Marshal.SizeOf <ShaderEffectTexture_NativeInterop>() * textureCount);
                for (int i = 0; i != textureCount; ++i)
                {
                    textures[i] = new ShaderEffectTexture_NativeInterop(ref desc.textures[i]);
                }
            }

            // allocate sampler heaps
            if (desc.samplers != null)
            {
                samplersCount = desc.samplers.Length;
                samplers      = (ShaderEffectSampler_NativeInterop *)Marshal.AllocHGlobal(Marshal.SizeOf <ShaderEffectSampler_NativeInterop>() * samplersCount);
                for (int i = 0; i != samplersCount; ++i)
                {
                    samplers[i] = new ShaderEffectSampler_NativeInterop(ref desc.samplers[i]);
                }
            }

            // allocate read-write-buffer heaps
            if (desc.randomAccessBuffers != null)
            {
                randomAccessBufferCount = desc.randomAccessBuffers.Length;
                randomAccessBuffers     = (ShaderEffectRandomAccessBuffer_NativeInterop *)Marshal.AllocHGlobal(Marshal.SizeOf <ShaderEffectRandomAccessBuffer_NativeInterop>() * randomAccessBufferCount);
                for (int i = 0; i != randomAccessBufferCount; ++i)
                {
                    randomAccessBuffers[i] = new ShaderEffectRandomAccessBuffer_NativeInterop(ref desc.randomAccessBuffers[i]);
                }
            }
        }