codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Allocate Memory  msg555 at 21:50 on Tuesday, April 12, 2005
 

I'm writing a String class, but I find I'm having trouble allocating memory. It contains two member variables, m_Length (int; the length of the string, not including the null at the end) and m_Char (* char to the contained string)

Upon debugging, I find that the same memory location is set to m_Char everytime for every instance of the class. Obviously this is a huge problem because every string I create points to the same string.

This is the function I created to allocate memory

void zString::Alloc(const unsigned int & Bytes)
{
if (m_Length) delete [] m_Char;
if (Bytes)
{
m_Char = new char[Bytes+1];
for(int i=0; i<=Bytes + 1; i++)
m_Char = '\0';
}
m_Length = Bytes;
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  send textarea name as a variable to function
•  ActionPerformed error
•  Re: Help me !!
•  menu template
•  Javascript help within ITIM
•  Help me debug this (object factories)
•  Re: How to open a MS Word document from Javascript
•  How to connect to oracle using java
•  Re: making controls visible one below another


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005