#ifndef MEM_NEW_FREE_H
#define MEM_NEW_FREE_H
#include "myXPU.h"
#include "myType.h"
#include "myHead.h"
#include "commStruct.h"
#include "memoryHandle.h"

class MemBasicManage {
    public:
        static struct DefaultBox *GetNewArrayDefaultBox(int num);
        static void RealeaseArrayDefaultBox(struct DefaultBox *boxList);

        static struct PredictBox *GetNewArrayPredictBox(int num);
        static void RealeaseArrayPredictBox(struct PredictBox *boxList);

        static struct Box *GetNewArrayBox(int num);
        static void RealeaseArrayBox(struct Box *boxList);

        static struct PicGroundTrueBox *GetNewArrayPicGroundTrueBox(int num);
        static void RealeaseArrayPicGroundTrueBox(struct PicGroundTrueBox *boxList);
        static void RealeaseArrayPicGroundTrueBoxMain(struct PicGroundTrueBox *boxList);
        static int *GetCopyCategoryList(int *srcCategoryList, int num);
        static struct Box *GetCopyBoxList(struct Box *srcBoxList, int num);
        static MyVoid *GetNewArrayCPUMyVoid(int fType, long long len);
        static void ClearArrayCPUMyVoid(int fType, MyVoid *hostMem, long long len);
        static void RealeaseArrayCPUMyVoid(char *hostMem);

        static char *GetNewArrayCPUChar(long long len);
        static void RealeaseArrayCPUChar(char *hostMem);
        static int *GetNewArrayCPUInt(long long len);
        static void RealeaseArrayCPUInt(int *hostMem);
        static float *GetNewArrayCPUFloat(long long len);
        static void RealeaseArrayCPUFloat(float *hostMem);
        static void ClearArrayCPUFloat(float *hostMem, long long len);
        static void ClearArrayCPUChar(char *hostMem, long long len);
        static void ClearArrayCPUInt(int *hostMem, long long len);
        static void MemHandleCopy(MemoryHandle *d, int dOffset, MemoryHandle *s, int sOffset, int len);
        static void MemTypeCopyToHandle(int sfType, int sID, MemoryHandle *d, int dOffset, MyVoid *s, MemType sMemType, int sOffset, int len);
        static void MemTypeCopy(int dfType, int sfType, int dID, int sID, MyVoid *d, MemType dMemType, int dOffset, MyVoid *s, MemType sMemType, int sOffset, int len);

#ifdef _CMEM_USE_GPU_
        static void RealeaseArrayGPUMyVoid(int devID, MyVoid *hostMem);
        static void ClearArrayGPUFloat(int devID, float *deviceMem, long long len);
        static void ClearArrayGPUFloatOffset(int devID, float *deviceMem, int offset, long long len);
        static void RealeaseArrayGPUFloat(int devID, float *deviceMem);
        static float *GetNewArrayGPUFloat(int devID, long long len);
        static char *GetGPUCharPoolMem(int devID, long long len);
        static char *GetGPUCharPoolMem(int devID, float factor, long long *outLen);

        static void GetGPUMemSize(int devID, size_t *freeLen, size_t *totalLen);
        static char *GetNewArrayGPUChar(int devID, long long len);
        static void RealeaseArrayGPUChar(int devID, char *deviceMem);
        static void ClearArrayGPUChar(int devID, char *deviceMem, int offset, long long len);
        static void CopyArrayGPUToGPU(int dfType, int sfType, int dID, int sID, MyVoid *yDst, int offsetD, MyVoid *ySrc, int offsetS, long long len);
        static void CopyArrayGPUToCPU(int dfType, int sfType, int devID, MyVoid *yDst, MyVoid *ySrc, int offfset,  long long len);
        static void CopyArrayCPUToGPU(int dfType, int sfType, int devID, MyVoid *yDst, int offset, MyVoid *ySrc, long long len);
        static void ArrayAddinArrayGPU(int fType, int devID, MyVoid *resultArr, MyVoid *aSrc1, MyVoid *aSrc2, int len);
        static void ArrayDotinArrayGPU(int fType, int devID, MyVoid *resultArray, MyVoid *inArray1, MyVoid *inArray2, int len);
        static void ClearArrayGPUMyVoid(int fType, int devID, MyVoid *hostMem, int offset, long long len);
        MyVoid *GetNewArrayGPUMyVoid(int fType, int devID, long long len);
#endif
        static void CopyArrayCPUToCPU(int dfType, int sfType, MyVoid *yDst, MyVoid *ySrc, long long len);
        static void ArrayAddinArrayCPU(int fType, MyVoid *resultArr, MyVoid *aSrc1, MyVoid *aSrc2, int len);
        static void ArrayDotinArrayCPU(int fType, MyVoid *resultArray, MyVoid *inArray1, MyVoid *inArray2, int len);
        static char *GetCPUCharPoolMem(float factor, long long *outLen);
        static char *GetCPUCharPoolMem(long long len);
        static PicInfo *GetNewPicInfo(int num);
        static void RealeasePicInfo(PicInfo *pInfo);
        static void RealeaseBatchSeqStruct(struct BatchSeqStruct *pBatchSeqStruct);
};

#endif
