Example #1
0
 /// <summary>
 /// Unmap() unmaps the given <code>ArrayBuffer</code> var from the module
 /// address space.  Use this if you want to save memory but might want to call
 /// Map() to map the buffer again later.  The<code>PP_Var</code> remains valid
 /// and should still be released using <code>PPB_Var</code> when you are done
 /// with the<code> ArrayBuffer</code>.
 /// </summary>
 public void Unmap()
 {
     PPBVarArrayBuffer.Unmap(ppvar);
     isMapped = false;
     dataMap  = null;
     dataPtr  = IntPtr.Zero;
 }
Example #2
0
        /// <summary>
        /// Map() maps the <code>ArrayBuffer</code> in to the module's address space
        /// and returns a pointer to the beginning of the buffer for the given
        /// <code>ArrayBuffer PP_Var</code>. ArrayBuffers are copied when transmitted,
        /// so changes to the underlying memory are not automatically available to
        /// the embedding page.
        ///
        /// Note that calling Map() can be a relatively expensive operation. Use care
        /// when calling it in performance-critical code. For example, you should call
        /// it only once when looping over an <code>ArrayBuffer</code>.
        ///
        /// <strong>Example:</strong>
        ///
        /// @code
        /// char* data = (char*)(array_buffer_if.Map(array_buffer_var));
        /// uint32_t byte_length = 0;
        /// PP_Bool ok = array_buffer_if.ByteLength(array_buffer_var, &byte_length);
        /// if (!ok)
        ///   return DoSomethingBecauseMyVarIsNotAnArrayBuffer();
        /// for (uint32_t i = 0; i < byte_length; ++i)
        ///   data[i] = 'A';
        /// @endcode
        /// </summary>
        /// <returns>
        /// A byte array with a copy of the data that is contained in unmanaged memory.
        /// </returns>
        public byte[] Map()
        {
            dataPtr = PPBVarArrayBuffer.Map(ppvar);
            var numBytes = ByteLength;

            dataMap = new byte[numBytes];
            if (numBytes > 0)
            {
                Marshal.Copy(dataPtr, dataMap, 0, dataMap.Length);
            }
            isMapped = true;
            return(dataMap);
        }
Example #3
0
 /// <summary>
 /// Creates a VarArrayBuffer of a particular size.
 /// </summary>
 /// <param name="size"></param>
 public VarArrayBuffer(uint size) : base(PPVarType.Undefined)
 {
     ppvar     = PPBVarArrayBuffer.Create(size);
     isManaged = true;
 }