# Difference between: "Array of T" and T^?

**URL:** https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839
**Category:** Oxygene
**Tags:** island, visual-studio, oxygene
**Created:** [April 23, 2017, 12:42pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839 "2017-04-23T12:42:05Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 23, 2017, 12:42pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/1 "2017-04-23T12:42:05Z")

</div>

Hellooooo,

i dont really know where is the actual difference between those array-Versions?

which to prefer and why?

–Shpend

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 23, 2017, 6:54pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/2 "2017-04-23T18:54:37Z")

</div>

You mean ^T right? ^T = pointer to T. Array of T is a managed dynamic array of T. Arrays have a length, are bounds checked and controlled by the compiler. ^T is a pointer to any T (or nil).

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 23, 2017, 7:27pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/3 "2017-04-23T19:27:29Z")

</div>

Ok, so for Array better never use ^T, except for some C-lvl-Code?

like, "memcpy(void\* from, void\* to, size\_t size);

> [@ck](#):
>
> Array of T is a managed dynamic array of T

Ok and what do you mean with: “managed”

Do you mean with it, what you wrote furthermore, or managed like in .NET?

And you said once a while, that internally, the ^T gets garbage collected very fast, what do you mean by that^^

would really like to know more about this!

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 24, 2017, 5:58am UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/4 "2017-04-24T05:58:25Z")

</div>

a pointer is a type that points to something else. There’s no garbage collection involved at all, it always points to something else.

An array of T is an actual array, you create it, it has X elements, you can ask for its length.

You generally should always use an array. It’s a safe type, the compiler will ensure things go right with it.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 24, 2017, 7:03am UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/5 "2017-04-24T07:03:49Z")

</div>

OK and where is the difference between :

```
Var a: ^T := New array of T

```

Is that still not garbage collected

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 24, 2017, 7:15am UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/6 "2017-04-24T07:15:38Z")

</div>

That’s going to be lost eventually when the GC hits. Don’t do that.

As I said before, pointer types are NOT considered GC objects.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 24, 2017, 8:23am UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/7 "2017-04-24T08:23:38Z")

</div>

Ok, and why is it possible then?

As i said, for C-lvl-Functions? or to enhence the possibilities in working with low-lvl api’s?

I am not pretty sure 😕

> [@ck](#):
>
> As I said before, pointer types are NOT considered GC objects.

Ah and how would they be deleted or freed?

via `DisposeAndNil(ptr)?`

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 24, 2017, 11:18am UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/8 "2017-04-24T11:18:22Z")

</div>

> [@shpend\_hoti](#):
>
> Ok, and why is it possible then?

Why pointers are a low level concept. And yes, among other things we use them to talk C apis.[quote=“shpend\_hoti, post:7, topic:12839”]  
Ah and how would they be deleted or freed?

via DisposeAndNil(ptr)?  
[/quote]

Depends on where you got them, if they point to an existing object you can’t free them at all.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 24, 2017, 1:22pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/9 "2017-04-24T13:22:19Z")

</div>

> [@ck](#):
>
> Depends on where you got them

What do you mean now by that??

when i get a “^MyCar( **record** )” cant i do just: DisposeAndNil(carPtr)??

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 24, 2017, 1:46pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/10 "2017-04-24T13:46:17Z")

</div>

No. DisposeAndNil calls IDisposable(object).Dispose. It does NOT free anything, the gc would take care of that. Also how would you allocate a new MyCar in the first place?

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [April 24, 2017, 2:03pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/11 "2017-04-24T14:03:42Z")

</div>

> [@ck](#):
>
> Also how would you allocate a new MyCar in the first place?

```
var car: MyCar; //ofc some init of this record
var carPtr := @car;

```

or

```
 var carPtr : ^MyCar := new MyCar[1]; //i know, that better not to do but you asked ^^

```

or do you want to Point something different out?

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 24, 2017, 2:18pm UTC](https://talk.remobjects.com/t/difference-between-array-of-t-and-t/12839/12 "2017-04-24T14:18:52Z")

</div>

> [@shpend\_hoti](#):
>
> var car: MyCar; //ofc some init of this record  
> var carPtr := @car;

carPtr points to car. It doesn’t copy it, it’s points to car. If car was on the stack, and carPtr stored somewhere else, it would point to a random place in the stack. You can’t free it at all (wouldn’t make sense?)

> [@shpend\_hoti](#):
>
> var carPtr : ^MyCar := new MyCar[1];

This creates a new array with 1 MyCar element, then points carPtr to the first element of it. This shouldn’t compile (there’s a bug report to disallow it). The underlying array will probably get gc’d the next time the GC hits.

You **really** should avoid pointers in most cases, unless you know what you are doing.
