You merely need to cast the pointer returned by MemPtrNew and assign it to a
variable of type struct data*.

   struct data* myPointer;

   myPointer = (struct data*)MemPtrNew(sizeof(struct data));

Bear in mind that myPointer may be NULL if there is no more memory left.

Also, check out MemHandleNew which allocates a movable memory chunk. See the
Palm Companion for discussion of memory management.

Matt

----- Original Message -----
From: "Dmitriy Tserekhman" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, December 23, 2002 5:43 PM
Subject: Dynamic Structures


> Hi,
>
> I am a starter in programming with Palm's SDK for Palm OS, and I am unable
> to find any guidelines on how to create and work with dynamic structures
> (structs).
>
> For example, I have the following struct declared:
>
> struct data
> {
>   UInt16 referenceID;
>   Boolean isSelected;
> };
>
> Then, I want to create a specified number of instances of type "data"
inside
> of a "for" loop structure depending on the runtime value of loop's counter
> variable. If I were to do this task in standard C++ then, I would have
used
> the following statement inside of a "for" loop to create such scenario:
>
> data * data_ptr = new data;
>
> The line above would assure that with each loop's iteration, a new memory
> location pointed by a pointer of type "data" would be allocated for the
> consequent instance of "data". (Later those memory allocations would have
to
> be explicitly released by "delete").
>
> To do such analogy with Palm OS API, I would have to use "MemPtrNew" API
> call to allocate nonmovable chunk of memory, but I still do not see how I
> would make that "MemPtr" to become a pointer of type "data" so that my
> application could use that pointer to explicitly access variables,
> "referenceID" and "isSelected" of struct "data".
>
> Thanks,
> Dmitriy Tserekhman.
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
>


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to