April 20, 2024, 03:46:25 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Pointer to array of pointers

Started by Parker, March 21, 2007, 04:04:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Parker

This topic is confusing me. I had some spare time and thought I'd make an ArrayList class (I need this for aeon's browser too), but I have a problem:

An ArrayList stores a pointer to an array of pointers. I know that in C I can call this void **array; but I'm having a little trouble making it work in Aurora. I know that Aurora only supports one level of indirection though it is possible to use more, but this is what is giving me trouble.

I have a pointer (void*) called "array" inside of the class. In the constructor, it is initialized to be an array of pointers (array = new(pointer, 10);). The problem I'm having is accessing it. There are many different syntaxes that compile but generate errors at runtime. Here are what I've tried:

  • *(pointer)array = ...
  • *(pointer)*(pointer)array = ...
  • *(pointer)(array) = ...
  • (*(pointer)array) = ...
  • Maybe others, I can't remember

I've run out of ideas. Please, how should I properly access the elements of the array?

Ionic Wind Support Team

Perhaps this will help you alng the way:


pointer *pa;
global sub main()
{
pa = new(int,100);
*pa[0] = AllocHeap(255);
*pa[1] = AllocHeap(255);
*(string)(*(pointer)pa[0]) = "This is a dynamically created string array";
*(string)(*(pointer)pa[1]) = "hello";
print(*(string)(*(pointer)pa[0]));
print(*(string)(*(pointer)pa[1]));

delete *pa[0] ;
delete *pa[1] ;
delete pa;
while (GetKey() = "") ;

}


NEW doesn't care about the type, although it does return that type to an unitialized pointer which can cause confusions.  The easiest way to handle it is to just use INT instead of POINTER in your NEW statement.  Which allocates the memory to the correct size.

Paul.
Ionic Wind Support Team

Parker

It turns out I was thinking too complicated. After looking at your example, I figured out all I needed to do was use pointer* as the type and *array[ i ] = ...

Thanks.