Re: How to allocate memory in c#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Stop working so hard. Use a collection!

Don't use arrays of things, use a generic collection such as List<B>.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





gol wrote:
Hi all,
I want to know how to allocate memory in c#? Or, maybe I don't need to do it. I'm quite new to c#, so I don't know many things.

Now, this is what I have in c#:

class A
{
private B[] MyArray;
private static int NumberofRecords = 0;
private int ArraySize = 10;
public A()
{
MyArray = new B[ArraySize];
}

public void AddRecord(string str)
{
MyArray [NumberofRecords] = new B(str);
NumberofRecords++;
if (NumberofRecords == ArraySize - 1)
{
ArraySize += 10;
RecordsArray = new B[ArraySize];
}
}
}

To clarify, the method AddRecord is the only place where the array grows bigger. Class B has a constructor receiving a string.

I guess my code is wrong here, anyhow this is the functionality that I want.(being able to let the array grow bigger, define exactly how much bigger, and not to "lose" what I had before).

Please help,
Thank you very much.

.



Relevant Pages

  • Re: What is the Fastest way for adding string items to some array/collection in sorted order?
    ... Test is performed to almost always add item at beginning of array, ... Private Declare Function StrArrAddItemSortedWD Lib "X.dll" As ... private arrcount as long ... szItemString is Empty String when API call returns ...
    (microsoft.public.vb.winapi)
  • Re: Issue designing a class module that uses OleLoadPicture
    ... There is a private sub that works on the byte array using the api ... Declare Function OleLoadPicture1 Lib "oleaut32" Alias ... Private m_hAccess As Long ... 'Device context for Access ...
    (comp.databases.ms-access)
  • Issue designing a class module that uses OleLoadPicture
    ... There is a private sub that works on the byte array using the api ... Private m_hAccess As Long ... 'Device context for Access ... Dim i As Long ...
    (comp.databases.ms-access)
  • Re: error with bin.base64 decoding
    ... Private Const mcClassName As String = "CBase64" ... Private Declare Sub RtlMoveMemory Lib "kernel32.dll" _ ... 'Encode encodes the byte array Source() to a string using the BASE64 ... 'Decode decodes a BASE64 encoded string to an one dimensional, ...
    (microsoft.public.vb.general.discussion)
  • Re: Double vector from C++
    ... Ralph schrieb: ... private MyVec() as t_Struct ... Private MyVec() As MyVecSub' not legal in VB ... An 'array' where each element is an 'array' of t_Structs. ...
    (microsoft.public.vb.general.discussion)