/// <summary> /// Maps a named shared memory region into process address space (creates or opens it) /// </summary> /// <param name="name">unique name of the shared memory region (should not contain [back]slashes to remain cross-platform).</param> /// <param name="create">whether we're creating it or just opening existing (created by some other process).</param> /// <param name="accessMode">mode which we will be accessing it (use values from ESharedMemoryAccess)</param> /// <param name="size">size of the buffer (should be >0. Also, the real size is subject to platform limitations and may be increased to match page size)</param> /// <returns>pointer to FSharedMemoryRegion (or its descendants) if successful, NULL if not.</returns> public static FSharedMemoryRegion MapNamedSharedMemoryRegion(string name, bool create, ESharedMemoryAccess accessMode, IntPtr size) { using (FStringUnsafe nameUnsafe = new FStringUnsafe(name)) { return(new FSharedMemoryRegion(Native_FMemory.MapNamedSharedMemoryRegion(ref nameUnsafe.Array, create, (uint)accessMode, size))); } }
/// <summary> /// Set up TLS caches on the current thread. These are the threads that we can trim. /// </summary> public static void SetupTLSCachesOnCurrentThread() { Native_FMemory.SetupTLSCachesOnCurrentThread(); }
public static IntPtr Memzero(IntPtr dest, ulong count) { return(Native_FMemory.Memzero(dest, count)); }
public static IntPtr Memmove(IntPtr dest, IntPtr src, ulong count) { return(Native_FMemory.Memmove(dest, src, count)); }
public static IntPtr Memset(IntPtr dest, byte value, ulong count) { return(Native_FMemory.Memset(dest, value, count)); }
public static IntPtr GPURealloc(IntPtr original, ulong size, uint alignment = DEFAULT_ALIGNMENT) { return(Native_FMemory.GPURealloc(original, size, alignment)); }
/// <summary> /// A helper function that will perform a series of random heap allocations to test /// the internal validity of the heap. Note, this function will "leak" memory, but another call /// will clean up previously allocated blocks before returning. This will help to A/B testing /// where you call it in a good state, do something to corrupt memory, then call this again /// and hopefully freeing some pointers will trigger a crash. /// </summary> public static void TestMemory() { Native_FMemory.TestMemory(); }
public static IntPtr SystemMalloc(ulong size) { return(Native_FMemory.SystemMalloc(size)); }
public static void SystemFree(IntPtr ptr) { Native_FMemory.SystemFree(ptr); }
public static void Memswap(IntPtr ptr1, IntPtr ptr2, int size) { Native_FMemory.Memswap(ptr1, ptr2, (ulong)size); }
public static void Memswap(IntPtr ptr1, IntPtr ptr2, ulong size) { Native_FMemory.Memswap(ptr1, ptr2, size); }
public static IntPtr StreamingMemcpy(IntPtr dest, IntPtr src, ulong count) { return(Native_FMemory.StreamingMemcpy(dest, src, count)); }
public static IntPtr BigBlockMemcpy(IntPtr dest, IntPtr src, ulong count) { return(Native_FMemory.BigBlockMemcpy(dest, src, count)); }
/// <summary> /// Unmaps a name shared memory region /// </summary> /// <param name="memoryRegion">an object that encapsulates a shared memory region (will be destroyed even if function fails!)</param> /// <returns>true if successful</returns> public static bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion memoryRegion) { return(Native_FMemory.UnmapNamedSharedMemoryRegion(memoryRegion.Address)); }
/// <summary> /// Clears the TLS caches on the current thread and disables any future caching. /// </summary> public static void ClearAndDisableTLSCachesOnCurrentThread() { Native_FMemory.ClearAndDisableTLSCachesOnCurrentThread(); }
public static IntPtr Malloc(int count, uint alignment = DEFAULT_ALIGNMENT) { return(Native_FMemory.Malloc((ulong)count, alignment)); }
public static IntPtr GPUMalloc(ulong count, uint alignment = DEFAULT_ALIGNMENT) { return(Native_FMemory.GPUMalloc(count, alignment)); }
public static IntPtr Realloc(IntPtr original, ulong count, uint alignment = DEFAULT_ALIGNMENT) { return(Native_FMemory.Realloc(original, count, alignment)); }
public static IntPtr GPUFree(IntPtr original) { return(Native_FMemory.GPUFree(original)); }
public static void Free(IntPtr original) { Native_FMemory.Free(original); }
/// <summary> /// Called once main is started and we have -purgatorymallocproxy. /// This uses the purgatory malloc proxy to check if things are writing to stale pointers. /// </summary> public static void EnablePurgatoryTests() { Native_FMemory.EnablePurgatoryTests(); }
public static ulong GetAllocSize(IntPtr original) { return(Native_FMemory.GetAllocSize(original)); }
public static int Memcmp(IntPtr dest, IntPtr src, ulong count) { return(Native_FMemory.Memcmp(dest, src, count)); }
public static ulong QuantizeSize(ulong count, uint alignment = DEFAULT_ALIGNMENT) { return(Native_FMemory.QuantizeSize(count, alignment)); }
public static IntPtr Memzero(IntPtr dest, int count) { return(Native_FMemory.Memzero(dest, (ulong)count)); }
/// <summary> /// Releases as much memory as possible. Must be called from the main thread. /// </summary> public static void Trim() { Native_FMemory.Trim(); }
public static IntPtr Memcpy(IntPtr dest, IntPtr src, uint count) { return(Native_FMemory.Memcpy(dest, src, count)); }
/// <summary> /// Changes the protection on a region of committed pages in the virtual address space. /// </summary> /// <param name="ptr">Address to the starting page of the region of pages whose access protection attributes are to be changed.</param> /// <param name="size">The size of the region whose access protection attributes are to be changed, in bytes.</param> /// <param name="canRead">Can the memory be read.</param> /// <param name="canWrite">Can the memory be written to.</param> /// <returns>True if the specified pages' protection mode was changed.</returns> public static bool PageProtect(IntPtr ptr, IntPtr size, bool canRead, bool canWrite) { return(Native_FMemory.PageProtect(ptr, size, canRead, canWrite)); }