# Space Rocks 3D!

**URL:** https://forum.makecode.com/t/space-rocks-3d/6334
**Category:** Show & Tell
**Tags:** game, featured-game
**Created:** [February 24, 2021, 3:59pm UTC](https://forum.makecode.com/t/space-rocks-3d/6334 "2021-02-24T15:59:47Z")
**Posts on this page:** 1
**Showing post:** 30

<div class="post-metadata">

### Author: ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)
#### Post date: [February 25, 2021, 5:28am UTC](https://forum.makecode.com/t/space-rocks-3d/6334/30 "2021-02-25T05:28:32Z")

</div>

> [@kwx](#):
>
> Thanks for the explanations, that’s good to know. If code is using an array of numbers where each element happens to fit in the unboxed 31bit size, does it then use roughly 4 bytes per entry also, so that there’s a single heap entry for the array content that contains the numbers directly? I’m using that quite extensively for coordinates and matrices, and I’m also trying to prefill and reuse them to avoid having them resized too frequently.

Yes, the array will take 4 bytes per element. As you add elements to the array it grows, so it may be slightly bigger than required. There is currently no way to avoid that.

> [@kwx](#):
>
> I’m unsure why the meowbit has memory issues, the first few levels shouldn’t have that much additional data that needs to be allocated.

There may be a memory leak somewhere. I take it the profiling in the browser doesn’t show any new objects staying alive after each frame/level?

> [@kwx](#):
>
> Overall, my approach was to use fixed point math with 7 bits after the decimal point for most of the speed critical loops, but sticking with floating point for once-per-frame operations such as updating the viewer matrix where accuracy and convenience were more important. Unfortunately it’s fairly easy to make mistakes and let a float number slip through which then slows things down elsewhere. It would be nice if there were a language feature to declare types to be integers and throw errors if that’s violated, but I guess that’s not what TypeScript is designed to do.

Yeah, TS unfortunately has only one number type, and it would be really difficult for us to change this.

The Fx module uses an abstract type and casting (which has no runtime cost) to keep this type-safe. You have to then say `Fx.add(a,b)` instead of `a+b`. You could do something similar, or just use the Fx module.

> <https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/fixed.ts>

---

_[View the full topic](https://forum.makecode.com/t/space-rocks-3d/6334)._
