1. 1.
    0
    panpa assagidaki kodda bir malloc problemi var duzeltir misin?

    using System;
    using System. Runtime.InteropServices;
    public unsafe class Memory
    {
    static int ph = GetProcessHeap();
    private Memory() {}
    public static void* Alloc(int size) {
    void* result = HeapAlloc(ph, HEAP_ZERO_MEMORY, size);
    if (result == null) throw new OutOfMemoryException();
    return result;
    }

    public static void Copy(void* src, void* dst) {
    byte* ps = (byte*)src;
    byte* pd = (byte*)dst;
    if (ps > pd) {
    for (; count != 0; count--) *pd++ = *ps++;
    }
    else if (ps < pd) {
    for (ps += count, pd += count; count != 0; count--) ---pd = ---ps;
    }
    }

    public static void Free(void* block) {
    if (!HeapFree(ph, 0, block)) throw new InvalidOperationException();
    }

    public static void* ReAlloc(void* block, int size) {
    void* result = HeapReAlloc(ph, HEAP_ZERO_MEMORY, block, size);
    if (result == null) throw new OutOfMemoryException();
    return result;
    }

    public static int SizeOf(void* block) {
    int result = HeapSize(ph, 0, block);
    if (result == -1) throw new InvalidOperationException();
    return result;
    }

    const int HEAP_ZERO_MEMORY = 0x00000008;

    [DllImport("kernel32")]
    static extern int GetProcessHeap();
    [DllImport("kernel32")]
    static extern void* HeapAlloc(int hHeap, int flags, int size);
    [DllImport("kernel32")]
    static extern bool HeapFree(int hHeap, int flags, void* block);
    [DllImport("kernel32")]
    static extern void* HeapReAlloc(int hHeap, int flags,
    void* block, int size);
    [DllImport("kernel32")]
    static extern int HeapSize(int hHeap, int flags, void* block);
    }
    ···
   tümünü göster