Memory Block vs Array

Are there any advantages or disadvantages to using either of these or is it just a comfort factor?

Dim myArray as INT64(12)
or
Dim myMB as new memoryblock(8*12)

Being Atomic on a 32 bit system isn’t relevant to this quest :slight_smile:

You can of course mimic an array with a memory block, but why? What do you want to achieve?

[quote=345213:@Jym Morton]Are there any advantages or disadvantages to using either of these or is it just a comfort factor?

Dim myArray as INT64(12)
or
Dim myMB as new memoryblock(8*12)

Being Atomic on a 32 bit system isn’t relevant to this quest :)[/quote]

these two are not equivalent

Dim myArray as INT64(12) // you get indexes 0 - 12 which is 13 items
or
Dim myMB as new memoryblock(8*13)

that said

  • resizing and array up & down is vastly simpler
  • operations on arrays simpler (sort, reverse, find element, etc)

why would you want to use a memory block for this ?

Right I meant array (11) not 12.
I’m not doing anything with it out side of collecting 12 Int64’s and putting them into a database.

Just practice something I’m not good with. outside of the mistake above :slight_smile:

Memoryblock will be faster. That said: it’s a bad idea to do it.

for SOME operations and an enormous pile of code for others

Personally I wouldn’t do this with a memory block at all
Not unless I needed to write all 12 in one column value but then why would you design a db to require that ? :stuck_out_tongue:

[quote=345213:@Jym Morton]Are there any advantages or disadvantages to using either of these or is it just a comfort factor?
[/quote]

Dim myArray as INT64(12) or Dim myMB as new memoryblock(8*12)
I agree with everyone’s comments so far. My suggestion would be to use an array and not use a MemoryBlock. The way that this can be viewed is by using an example to build a car.

Using an array is similar to building a car with parts that already fit together, such as doors, tires, steering wheel, etc. It may not be perfect, and it is really good at building a vehicle quickly with very few problems. Yes, the car may only be able to travel 60 miles-per-hour, and when that is the speed limit, then that is good. The car will be able to drive reliably across the country. Many of the bugs have been worked out of the design and there has been much optimization performed for you.

Building an array with a MemoryBlock is like building a car from raw materials, such as raw metal. The good news is that you get to design, create, weld, and are responsible for every small detail of the car. Building a car (MemoryBlock) in this way will take considerably more time. If there are any issues then you are responsible for fixing them. Sure, you may be able to have the car go 120 miles-per-hour, and this will only last for a small amount of time, as it will not be as reliable. If you have a team of designers to build a good system, then this would be an option. For most programmers with smaller companies, this would use up many valuable resources that can be used to help build the company.

An array is easier to program than a MemoryBlock. If you have lots of time, then you can build a fast MemoryBlock.

I like the array method better :slight_smile:

Spot on! And don’t forget, if there is a problem with the car (MemoryBlock) and another car mechanic looks at it (because you’re sick, or other things) he would have to dissassemble the whole car to simply understand what causes the problem.