Virtual Humans Forum
Virtual Humans Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Virtual Humans
Partner website:
Chatbots.org
 All Forums
 Virtual Humans
 Programming
 Object Pascal, Free Pascal(FPC/FPK), Lazarus IDE
 New Topic  Reply to Topic
 Printer Friendly
Previous Page | Next Page
Author Previous Topic Topic Next Topic
Page: of 7

GrantNZ
Moderator



New Zealand
2677 Posts

Posted - Aug 28 2009 :  06:45:39  Show Profile  Reply with Quote
Sounds like you're on the right track.

In C++ you use the "new" command to create an array (or any other object) on the heap. "new" returns a pointer to the heap memory, which you then store in a pointer variable. This is as opposed to just creating the array/object, in which case it is stored in the stack, which has limited space.

In my experience (which doesn't really apply to Pascal ), a "static array" has a fixed-size (defined at compile-time), and lives on the stack. A "dynamic array" can have any size (defined at run-time), and is stored in the heap.

The "stack" is kind of limited-size scratch-memory, useful for small and/or short-term variables. (In C++ you can choose the size of the stack when you compile.) You typically use it for things like loop counters, and small variables carried throughout your program.

The "heap" is all other memory. In C++, anything on the heap is accessed through a pointer, and you have to explicitly create and destroy things on the heap (otherwise you end up with memory leak problems). You typically use the heap for all the mass data that your program is using, so that would be large objects, arrays, etc.

Hope this helps.... I have no idea how the paradigms transfer to Pascal (or especially the Pascal syntax!) but I suspect most of the concepts should be applicable.
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Aug 28 2009 :  08:54:35  Show Profile  Visit hologenicman's Homepage  Reply with Quote
I remember the "new" in C++ and having to explicitley destroy it when no longer needed.

I have been looking for such an item in Pascal, but I just haven't been smart enough to find it quite yet...

I'm really hoping that this is just going to be an alternate way of creating the object and that it will leave all the rest of my array templating and make-up alone.

Actually as it is now, I create the arrays, and then immediately create pointer for the arrays so that i can sort the arrays around as needed. If the Pascal equivalent of "new" works this way, then I should not have too much trouble with it...

I can destroy it easy enoug during the Finalization section of the AI script which runs at shutdown of the application.

I am trying to avoid Dynamic arrays due to my current array structure and throughput. I believe that I had tried some dynamic arrays at first but found that the HologenicMatrix has to bedefined for size from the very start so that the throughput can be dependably established. I may be wrong on this point, and I would really like the array to be dynamic so that it can be expanded at a later point without having to destroy the existing matrix of learned information in the process. I'll come back and revisit this issue at a later point during the pollishing stages of the application.

Thanks,
John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 18 2009 :  04:19:07  Show Profile  Visit hologenicman's Homepage  Reply with Quote
This is a link that Grant posted for me:
http://www.geocities.com/franzglaser/tpsrc/tp_dynarr.html

I have been reading through it to try to adapt my code to create the array on the "heap" instead of on the "stack".

It seems that the following bit of info is where my answer lies:

quote:
Array of Pointers
Beginners read all records from the file into memory in one single chunk. This is primitive and has some serious drawbacks. Usually there should be a means to add and remove records, but how to do that with one single memory block?

It is much better to declare an array of pointers to single records:

Type APers = Array[1..1999] of ^TPersRec;

This needs 8kB of memory for the pointers (assumed 4 byte for each pointer).

Whenever you create a new person - record, you simply
New(APers[UU]);
obtaining memory from the heap in small chunks of record size. It needs a little more programming, but it is worth the effort for flexibility.

To access it use:
APers[nn]^.Age := 34;




Currently, I create my arrays and then point to them with arrays of pointers.

According to the above tesxt, I will adapt the arrays over to being created from the beginning as arrays of pointers and try to get my existing software to gracefully accept the change...

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.

Edited by - hologenicman on Sep 18 2009 04:23:38
Go to Top of Page

GrantNZ
Moderator



New Zealand
2677 Posts

Posted - Sep 18 2009 :  05:56:12  Show Profile  Reply with Quote
In C++, that kind of conversion is usually pretty smooth-sailing - the arrays behave much the same except for those differences when they are created and deleted. Hopefully the same will be true for you in Pascal
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 18 2009 :  09:53:17  Show Profile  Visit hologenicman's Homepage  Reply with Quote
I'm sure that it is just my ignorance in this case...

I have put the pMatrix = array[1..3, 0..11] of ^TMatrix;
into the type section instead of the variavle section of the script so that pMatrix is not a type instead of a variable.

I've commented out my original cascade variable creations such as InputCascade0: TMatrix; // Write
from the variable section.

I've also removed the Pointer asignment of the addresses for those variable as as in pMatrix[1, 0]:= @InputCascade0;

I've put in New(pMatrix[1, 0]);
for each of the needed matrix positions...

I'm rereading the syntax and trying to figure out how to properly do it.

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.

Edited by - hologenicman on Sep 18 2009 09:59:21
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 18 2009 :  13:14:47  Show Profile  Visit hologenicman's Homepage  Reply with Quote

Got it working!!

It took me until 4AM, but I got the memory allocation to take place on the heap and was able to build the HologenicMatrix up to 10GB in RAM.

The code is actually much cleaner now as well...

Now I have started doing little adjustments in the matrix and it's functionallity. This means that i am back to the fun part of the project.

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page

GrantNZ
Moderator



New Zealand
2677 Posts

Posted - Sep 19 2009 :  10:02:06  Show Profile  Reply with Quote
You're not a true programmer until you've been interrupted by a sunrise Just kidding of course - get some sleep!!!

I'm glad you've got past that obstacle - programming sometimes seems like an endless racetrack full of hurdles - I'm looking forward to seeing your further developments
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 19 2009 :  23:22:02  Show Profile  Visit hologenicman's Homepage  Reply with Quote
Thanks, Grant.

The next issue that I went on to figure out is the issue of writting the cascade matrixes to a file for storage and retrieval.

It all works, but I am interested in having the variable that is read to or written from be a variable that is created on the heap for the same memory reasongs as my recent troubles.

It works fine when I read the dereferenced matrix pointer to an interval variable that is written on the stack and then read or write from that stack variable:

Read(HologenicCoreFile, HologenicCore); // read contents to Cascade
               pMatrix[2, CountCascade]^:= HologenicCore;


pMatrix[]^ is the dereferenced pointer. When I try to put it directly into the read or write function it compiles, but just fails to write the file:

Read(HologenicCoreFile, pMatrix[2, CountCascade]^); // read contents to Cascade
 


I'm suspicious that it may just be a simple thing such as puting () around the derereferenced pointer or such...?

For now, my solution is to just leave it as it is and move onto some of the new fun stuff that my recent RAM expansion success has opened up to me.

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.

Edited by - hologenicman on Sep 19 2009 23:23:37
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 19 2009 :  23:33:52  Show Profile  Visit hologenicman's Homepage  Reply with Quote
With the attaining of expanded use of my installed RAM, I have reached a personal landmark of sorts. The following is an excerpt from my change-log:


(9/17/09)
Major re-write to create the majority of 
the matrix memory on the "heap" instead 
of on the stack.

(9/18/09)
Failed to be able to get a derereferenced 
pointer(heap mamory) to work with the read/write 
to File functions.  Seems to need to have a 
variable that is stored on the stack...?

(9/19/09)
Removed button for initializing th ematrix 
from the app interface form.  This prevents 
the redundant creation of new matrix arrays 
on the heap.

(9/19/09)
Put the variables for functionallity control 
into the individual nodes in template.  
This is closer to being able to write the 
actual node-code.  

With dimensions of 16:IO, 32:Cerebellum, 
64:AV, and 64:Cerebrum only using 9GB of 
RAM, I am ready to either start working on 
the multithreading code or on the actual 
Node-code itself.


John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.

Edited by - hologenicman on Sep 19 2009 23:43:19
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 20 2009 :  18:37:53  Show Profile  Visit hologenicman's Homepage  Reply with Quote

Been doing some clean-up work.

I have moved some values from the "type" section into the "Const" section so that I can configure the compile from a single place more efficiently. This is similar to #define (I believe) as used in C.

Actually, const in Pascal/Delphi is the same as const in C/C++. What I was really looking for was a true equivalent to #define, but I haven't found it.

The const worked just fine for moving values up from the type(templates), but when I tried to use a const value in the "for" loops within the program I get a message that the identifier is already defined. It is acting like the for loop is trying to re-define the identifier. This confuses me since I can use a declared variable for the very same need in the function code without a problem...?

Oh, well, #define would probably work better if I could find it's use for pascal. I've been doing yahoo searches and coming up empty. Perhaps I should move over to Google for a while.

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 21 2009 :  10:01:48  Show Profile  Visit hologenicman's Homepage  Reply with Quote

I got the {$define SOMETHING := 16} to work.

It turns out that I had to enable C-style macros in the compiler settings.

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 21 2009 :  11:05:07  Show Profile  Visit hologenicman's Homepage  Reply with Quote

Still having troubles getting those three identifiers into the const or defines.

They act as though they are being re-declared in the coed, but I can't figure out where they are being re-declared...?

John L>
IA|AI

HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page

laackejim
Committed Member



USA
3274 Posts

Posted - Sep 21 2009 :  15:52:23  Show Profile  Reply with Quote
Pascal is drifting further and further away in my head so this question may not be relevant.

If you enable C type macros is it possible that you must disable the default approach?

Uncle Jim (e=mc2)
Go to Top of Page

GamerThom
Dedicated Member



USA
2550 Posts

Posted - Sep 21 2009 :  16:51:22  Show Profile  Visit GamerThom's Homepage  Click to see GamerThom's MSN Messenger address  Reply with Quote
Hmmmmmm.......... could be, Jim.
I seem to remember something about that when
when I was studying programming back in "81".

Having both C-style and default active will
keep cycling and redeclaring the special identifiers.

But I dropped the pascal programming after
a few weeks in favor of BASIC and cobol.
Dropped cobol too after a couple weeks.

http://www.gamerthom.com/ IAlAI

Edited by - GamerThom on Sep 21 2009 17:08:47
Go to Top of Page

hologenicman
Moderator



USA
3318 Posts

Posted - Sep 21 2009 :  22:47:54  Show Profile  Visit hologenicman's Homepage
Thanks, Guys.

Sad to say, though, that the issue has to be in the functions themselves because I have the very same problem whether I am puting the declaration into the "define"(with C-macro) or into the "const". Both instances act as though the functions are re-declaring the identifier.

It's a bit of a head scratcher for me...

The value is only really used in a few "for" statements where I use it to establish the iterations. I have been suspicious of whether the For-statements are trying to re-create the identifier on a local scope...?

John L>
IA|AI




HologenicMan
John A. Latimer
http://www.UniversalHologenics.com

"If the Human brain were so simple that we could understand it,
we would be so simple that we couldn't..."
-Emerson M Pugh-

Current project:http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=816&whichpage=1

DISCOVERY: The more I learn, the more I learn how little I know.
GOAL: There's strength in simplicity.
NOTE: Goal not always achieved.
Go to Top of Page
Page: of 7 Previous Topic Topic Next Topic  
Previous Page | Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Virtual Humans Forum © V.R.Consulting Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000