Character memory dynamic allocation management class (Cautomem)

xiaoxiao2021-04-05  233

#if! defined (AFX_CAUTOMEM_H__ENCLUDED _) # Define AFX_CAUTOMEM_H__INCLUDED_

/ ************************************************** *************** /// Name: automem.h // function: Character memory dynamic allocation management class (Cautomem) declaration, mainly for //: Complete New Out of a memory, Before the process of program delete memory //: An abnormality, resulting in this segment memory leak; introduced into the C hop to save from //: The release mechanism, effectively solve this problem .//copyright: Radfort // Author: hzh // Date: 2006-06-21 / ************************************************************ ******************* /

Class Cautomem {private: unsigned int m_size;

Char * m_buff; // Cautomem (Cautomem & RHS); // Cautomem & Operator = (Cautomem & RHS); public: Cautomem (unsigned int nsize); // copy constructor Cautomem (Const Cautomem & RHS);

~ Cautomem (Void); // Assignment Operator Cautomem & Operator = (const cautomem "; // Get memory start address char * GET (VOID) Const;

// Air Distribution Memory Char * Set (Void) Const;

/ / Reassign the memory void renew;

// Get the length of the distribution of memory unsigned int layth () const;};

#ENDIF

/ ************************************************** ******** //// name: automem.cpp // function: Character memory dynamic allocation management class (CAUTOMEM) implementation // Copyright: Radfort // Author: hzh // Date: 2006-06-21 / ************************************************** ********* /

#include "automem.h"

/ ************************************************** *************** / //// name: cautom // function: Constructor // Access: public // Para: None // Return: of no available // author: Hzh // Date: 2006-06-20 / ****************************************************** ************************** / CAUTOMEM :: Cautomem (unsigned int nsize): m_size (nsize), m_buff (new char [m_size]) {MEMSET (m_buff, 0, m_size);}

/ * Cautomem :: Cautomem (Cautomem & RHS) {m_buff = new char [rhs.Length ()]; if (m_buff) {memcpy (m_buff, rhs.get (), rhs.length ());}} * // / Copy Construction Function Cautomem :: Cautomem (Const Cautomem (CONST CAUTOMEM & RHS) {m_buff = new char [rhs.Length ()]; if (m_buff) {memcpy (m_buff, rhs.get (), rhs.length ());}}

// Assignment Operator Cautomem & Cautomem :: Operator = (const cautomem) {if (this == & rhs) {Return * this;}

IF (m_buff) {delete [] m_buff; m_buff = NULL;

m_buff = new char [rhs.Length ()]; if (m_buff) {memcpy (m_buff, rhs.get (), rhs.Length ());}

Return * this;}

/ * Cautomem & Cautomem :: Operator = (Cautomem & RHS) {if (this == & r Hs) {Return * this;}

IF (m_buff) {delete [] m_buff; m_buff = NULL;

m_buff = new char [rhs.Length ()]; if (m_buff) {memcpy (m_buff, rhs.get (), rhs.Length ());}

Return * this;} * /

// Automatic destructure release memory Cautomem :: ~ Cautomem (void) {delete [] m_buff; m_buff = null;}

// Get memory start address char * cautomem :: get (void) const {return m_buff;}

// Get the length of the distribution of memory Unsigned int Cautomem :: Length () const {return m_size;}

// Air Distribution Memory Char * Cautomem :: Set () const {memset (m_buff, 0, m_size); return m_buff;}

/ / Re-allocate memory void cautomem :: rent (unsigned int nsize) {if (m_buff) {delete [] m_buff; m_buff = null;} m_size = nsize; m_buff = new char [m_size]; MEMSET (m_buff, 0, m_size }

转载请注明原文地址:https://www.9cbs.com/read-132078.html

New Post(0)