Board index » delphi » Beginner needs some pointers with pointers!
Anthea Webber
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Anthea Webber
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Beginner needs some pointers with pointers!
How exactly do pointers work? I have a very basic understanding of what
they do, by I'm not sure how to properly use them. When do you use "new()" ? What's the difference between P : ^TWhaterver; What happens if you have a pointer pointing to another pointer? I'd really appreciate some help, or somewhere where I can find help? |
Ing. Franz Glase
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Beginner needs some pointers with pointers!QuoteAnthea Webber wrote: page "FAQ", article "Turbo Pascal memory considerations, Pointer primer" :-) Franz Glaser |
Mike Copela
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Beginner needs some pointers with pointers!Quote> How exactly do pointers work? I have a very basic understanding of what compiler. Quote> and told how much data it points to. Quote> What happens if you have a pointer pointing to another pointer? Pointers are variables within a (Pascal) program which reference Type BUFF = array[0..8191] of char; { large buffer type } This example shows use of an 8K (large) Text file buffer. The buffer Type REC = record { sample record structure } Some things to understand about the above P/A code: Linked Lists require more code and logic than I can show here (but I |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Beginner needs some pointers with pointers!QuoteIn article <7c637m$2k...@news3.saix.net>, Anthea Webber <a...@yebo.co.za> wrote: is you allocate a specific target variable. Use getmem() when you know it only on run time. Consider the following ways to allocate a pointer to string and assign the target: var p:^string; new(p); getmem(p,length(st)+1); The first always allocates 256 bytes no matter how short the string is. Then thee is the stupid way to use getmem: getmem(p,sizeof(p^)); this Quote
p^:=<variable of type Twhatever>. The latter is just an abstract pointer that does not point to anything specific. For example if you write a memory allocation function: function alloc(x:word):pointer; You would not have to care for the specific type of the target variable Quote>What happens if you have a pointer pointing to another pointer? Quote>I'd really appreciate some help, or somewhere where I can find help? |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Beginner needs some pointers with pointers!In article <MPG.11508531cc3ec874989...@news.primenet.com>, QuoteMike Copeland <mrc...@primenet.com> wrote: allocation. Quote
pointer holds the address (segment:offset) of the variable that it points. Quote> Note that a given technique (e.g. linked lists) is not always the Procedure SortList(var p:pnode); find the middle point and put it in mp, cut the list in sortlist(p); Merge lists p and mp and put the result in p; If one passes also the length then it comes somewhat simpler and faster Osmo |
Mike Copela
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Beginner needs some pointers with pointers!Quote> > Note that a given technique (e.g. linked lists) is not always the execution) than that required to sort array data - pointer array or direct data. So, we disagree. I know which method I'd choose... |