Пример #1
0
 /// <summary>
 /// This function will be called by a native function that is required to
 /// return a SharedPtr. It will process the native object and shared
 /// pointer and create a managed side sharedPtr and wrapper if needed.
 /// This sharedPtr will stay around until the collection detects that is
 /// has no more open handles. In order for this to happen at least one
 /// SharedPtr must be checked out, which will happen naturally since you
 /// want to return one anyway from the function that called the native
 /// function that called back to here.
 /// </summary>
 /// <param name="nativeObject">The object stackSharedPtr points to.</param>
 /// <param name="stackSharedPtr">A SharedPtr on the stack from ogre.</param>
 public void processWrapperObject(IntPtr nativeObject, IntPtr stackSharedPtr)
 {
     if (nativeObject != IntPtr.Zero && !ptrDictionary.ContainsKey(nativeObject))
     {
         SharedPtrEntry <T> entry = new SharedPtrEntry <T>(createWrapper(nativeObject), nativeObject, createHeapSharedPtr(stackSharedPtr));
         ptrDictionary.Add(nativeObject, entry);
     }
 }
Пример #2
0
        /// <summary>
        /// Return a pointer to this collection. This is done in the SharedPtr
        /// dispose method. If all the references are returned the entry will be
        /// disposed and the heap allocated shared pointer will be released.
        /// </summary>
        /// <param name="sharedPtr"></param>
        public void returnPtr(SharedPtr <T> sharedPtr)
        {
            IntPtr             key   = sharedPtr.NativeObject;
            SharedPtrEntry <T> entry = ptrDictionary[key];

            entry.removePointer(sharedPtr);
            if (OgreInterface.TrackMemoryLeaks)
            {
                allocationStackTraces.Remove(sharedPtr);
            }
            if (!entry.HasReferences)
            {
                ptrDictionary.Remove(key);
                deleteHeapSharedPtr(entry.HeapSharedPtr);
                entry.Dispose();
            }
        }