예제 #1
0
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            // Build our name
            String strName = GetMemorySectionName();

            IntPtr mappedFileHandle;

            // This gets shared memory for our map.  If its can't, it gives us clean memory.
            Byte *pMemorySection = EncodingTable.nativeCreateOpenFileMapping(strName, iSize, out mappedFileHandle);

            Contract.Assert(pMemorySection != null,
                            "[BaseCodePageEncoding.GetSharedMemory] Expected non-null memory section to be opened");

            // If that failed, we have to die.
            if (pMemorySection == null)
            {
                throw new OutOfMemoryException(
                          Environment.GetResourceString("Arg_OutOfMemoryException"));
            }

            // if we have null file handle. this means memory was allocated after
            // failing to open the mapped file.

            if (mappedFileHandle != IntPtr.Zero)
            {
                safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)pMemorySection, true);
                safeFileMappingHandle   = new SafeFileMappingHandle(mappedFileHandle, true);
            }

            return(pMemorySection);
        }
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            IntPtr ptr;
            byte * numPtr = EncodingTable.nativeCreateOpenFileMapping(this.GetMemorySectionName(), iSize, out ptr);

            if (numPtr == null)
            {
                throw new OutOfMemoryException(Environment.GetResourceString("Arg_OutOfMemoryException"));
            }
            if (ptr != IntPtr.Zero)
            {
                this.safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)numPtr, true);
                this.safeFileMappingHandle   = new SafeFileMappingHandle(ptr, true);
            }
            return(numPtr);
        }
예제 #3
0
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            IntPtr mappedFileHandle;
            byte * openFileMapping = EncodingTable.nativeCreateOpenFileMapping(this.GetMemorySectionName(), iSize, out mappedFileHandle);

            if ((IntPtr)openFileMapping == IntPtr.Zero)
            {
                throw new OutOfMemoryException(Environment.GetResourceString("Arg_OutOfMemoryException"));
            }
            if (mappedFileHandle != IntPtr.Zero)
            {
                this.safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)((void *)openFileMapping), true);
                this.safeFileMappingHandle   = new SafeFileMappingHandle(mappedFileHandle, true);
            }
            return(openFileMapping);
        }