CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Allocate Memory

Threaded View

  1. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Allocate Memory

    One question:

    Why aren't you using, at the very least, the basic <string.h> functions in your class or even functions such as memcpy() when copying one buffer to another?

    For example:
    Code:
    zString::zString(const char * const rhs)
    {
        for(m_Length=0; *(rhs+m_Length)!='\0'; m_Length++) {} //Find first Null
        Alloc(m_Length);
        for (int i=0; i<m_Length; i++)
            (*this)[i] = *(rhs+i);
    }
    There is no need to code loops to find the length of a null-terminated string, or loops to copy data.
    Code:
    zString::zString(const char * const rhs)
    {
        m_Length = strlen(rhs);
        Alloc(m_Length);
        memcpy(m_Char, rhs, m_Length);
    }
    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 12th, 2005 at 05:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured