Topic:   programming TI-BASIC   (Read 25663 times)


0 Members and 1 Guest are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #30 on: October 29, 2011, 10:13:41 AM »
X is correct, Tnt Basic is vastly different than C or any of it's variants.

Memory management isn't so bad. If you allocate it, just free it when you're done with it.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #31 on: October 29, 2011, 09:52:13 PM »
I've never touched TNT BASIC or any other BASIC dialect other than GML so I don't have much input there. But I do agree with Gan that memory management isnt that bad, personally I prefer extream measures so that I have as little memory allocated at max. My recent programs have been riddled with define statements and obscure functions. All to save those two bytes.
« Last Edit: October 29, 2011, 09:52:55 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: programming TI-BASIC
« Reply #32 on: November 01, 2011, 02:20:50 AM »
Quote
I've never touched TNT BASIC or any other BASIC dialect other than GML so I don't have much input there. But I do agree with Gan that memory management isnt that bad, personally I prefer extream measures so that I have as little memory allocated at max. My recent programs have been riddled with define statements and obscure functions. All to save those two bytes.

Ironically every define statement and function declaration (and call) you make takes up the same (probably more) memory on the stack, instead of the heap.

Also memory management is never easy, anyone who says it is has a memory leak in their brain. Or at least its easy till you start having to do some serious programming with complex data structures. I challenge anyone here to write a self balancing binary tree in C that doesn't have a memory leak without significant debugging.
« Last Edit: November 01, 2011, 02:27:06 AM by x »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #33 on: November 01, 2011, 07:43:46 AM »
Ooh! I believe that's my next project in my programming class...
Except it's in C#.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #34 on: November 01, 2011, 03:47:43 PM »
oh i see what you mean 0.o the existence of something like that never crossed my mind.

Gan why would you do something in C#, isn't that a windows programming language?
and there's some dude who did articles about these things. In C#


http://msdn.microsoft.com/en-US/library/ms379572(v=VS.80).aspx
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #35 on: November 01, 2011, 05:37:36 PM »
College classes, they force you to the dark side.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #36 on: November 01, 2011, 06:37:35 PM »
that sucks. :/ I hear that they don't really have cookies.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #37 on: November 01, 2011, 07:07:01 PM »
Actually, quite a few times I've walked out of my college library to be surprised by cookies and even full meals.
The dark side does have it's benefits.
« Last Edit: November 01, 2011, 07:07:49 PM by Gandolf »

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #38 on: November 03, 2011, 03:39:14 PM »
thats good cookies always make everything better.
So why are you doing it in C# instead of Obj-C or C?
do you have a class for that language?
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #39 on: November 03, 2011, 04:06:08 PM »
Yeah. It's a Data Structure class and they only use C#.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #40 on: November 04, 2011, 05:07:42 PM »
that sucks, it seems like they always force you to use languages and computers made by microsoft. :o
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: programming TI-BASIC
« Reply #41 on: November 05, 2011, 06:11:39 AM »
Quote
Yeah. It's a Data Structure class and they only use C#.

C# is Microsofts rip-off of Java. Also they use it because it has a GC and thus no forced memory management -- thus implementing data structures is easy. Its NOTHING like trying to implement the same thing in C.

Also I doubt you have to implement a proper self balancing binary tree as a first thing in an intro DSA course. Although having said that I had to do a splay tree (look it up, those things are nuts) as my project way back when I did my data structures course.
« Last Edit: November 05, 2011, 06:14:07 AM by x »

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: programming TI-BASIC
« Reply #42 on: November 05, 2011, 08:57:56 AM »
Quote

Ironically every define statement and function declaration (and call) you make takes up the same (probably more) memory on the stack, instead of the heap.

Also memory management is never easy, anyone who says it is has a memory leak in their brain. Or at least its easy till you start having to do some serious programming with complex data structures. I challenge anyone here to write a self balancing binary tree in C that doesn't have a memory leak without significant debugging.

I submit!!!
I tried reallocating an array to a larger size, and although the concept of malloc(), calloc(), realloc(), and free() seems simple when you read it, but then you try it, and

IT DEALLOCATES YOUR SANITY
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: programming TI-BASIC
« Reply #43 on: November 05, 2011, 01:43:58 PM »
Bleh, I wrote a dynamic C array and wouldn't advise using realloc. There's a chance of losing data.

x


  • GMG-er

  • **


  • Posts: 247
Re: programming TI-BASIC
« Reply #44 on: November 05, 2011, 09:28:45 PM »
Quote
Bleh, I wrote a dynamic C array and wouldn't advise using realloc. There's a chance of losing data.

No theres not, unless:
a) You're doing it wrong.
b) Theres not enough RAM available on heap; this will however return an error which you can deal with.

I've used realloc to create a resizing binary heap which is currently being used every day on an extremely active business application -- never had a single error or amnesic episode. Also there are no std library c/c++ functions that will have a chance of not working properly. In fact on the official C++ website:
"The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved."
The memory is GUARANTEED to be preserved.

Here is some example code of correct usage I wrote for the above mentioned application:
Code: [Select]
//check if the heap is full
if (h->index >= h->blockSize) //if the index is the block size, it is pointing outside the block and the block is full
    {
 Â        //if the heap is at capacity, return with error
 Â       Â if (h->blockSize >= MAXELEMENTS){
 Â           puts("Error: The heap has reached its maximum size");
 Â           return;
 Â       Â }
 Â       //otherwise resize the heap
 Â       // try to reallocate
 Â       printf("%d\\n", h->index);
 Â       void* temp = realloc(h->block, sizeof(ELEMENT)*h->blockSize+BLOCKINCREMENT);
 Â       if (temp == NULL){ //if reallocate fails, report the error, then end the function
 Â           puts("Could not realloc memory");
 Â           return;
 Â       }
 Â       //if reallocate is successful, update state variables
 Â       h->blockSize += BLOCKINCREMENT; //incremenet the size
 Â       h->block = temp; //get the new block
 Â   }
« Last Edit: November 05, 2011, 09:30:05 PM by x »