Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: I made a database class of sorts  (Read 1862 times)

0 Members and 1 Guest are viewing this topic.
I made a database class of sorts
« on: October 01, 2008, 10:46:03 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
http://crystalrook.sitesled.com/HVSTDAT.zip

Yea, well I was sick of not being able to use linked lists (because I'm an idiot.)  So I went and wrote this.  I'll be updating it from time to time since it's a part of the engine I'm working on (Harvest Engine, hence the name HVSTDAT.)  I'd appreciate it if anyone tells me about any problems they may find in it or if they'd like me to add something in my updates.

I've put examples for each function in the main function.

EDIT: Made some updates to address the issues that Nits pointed out.
« Last Edit: October 17, 2008, 02:21:42 am by MG-Zero »
Logged



i love big weenies and i cannot lie
Re: I made a database class of sorts
« Reply #1 on: October 03, 2008, 07:59:39 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
Linked Lists have the advantage of being (relatively) quick. This looks like it'd be rather...slow..repeatedly copying all the data (not to mention all the constructor/destructor problems that can arise from this) :P
Logged
Re: I made a database class of sorts
« Reply #2 on: October 03, 2008, 08:04:37 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Iteration and random access would probably be pretty fast given that your using arrays. However adding and removing data (usually done very often with linked lists) is going to be horribly slow. Allocation and deallocation of memory is a pretty time intensive task.

On another note, I see you like my file-header format XD.
Logged
Re: I made a database class of sorts
« Reply #3 on: October 04, 2008, 05:37:55 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
I know quite recently I've taken a liking for BS trees for scene graph manipulation.
Logged
Re: I made a database class of sorts
« Reply #4 on: October 04, 2008, 04:12:23 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Iteration and random access would probably be pretty fast given that your using arrays. However adding and removing data (usually done very often with linked lists) is going to be horribly slow. Allocation and deallocation of memory is a pretty time intensive task.

On another note, I see you like my file-header format XD.

Yes, I stole your header format lmao.

Well, I'm working on optimization currently, so i'll see if I can figure out a faster way to add and remove data.  Hell, I'm just !@#$% happy that I got this working hahaha
Logged



i love big weenies and i cannot lie
Re: I made a database class of sorts
« Reply #5 on: October 15, 2008, 06:04:00 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 256
I'm curious as to why you don't just use a little STL lovin'?
Logged
  • My Myspace?
Re: I made a database class of sorts
« Reply #6 on: October 15, 2008, 06:29:24 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Because I wanted to program something that works for once haha.
Logged



i love big weenies and i cannot lie
Re: I made a database class of sorts
« Reply #7 on: October 15, 2008, 11:27:05 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 256
Ah, well, that makes sense ^_^.

I remember the first template class I wrote. I was like "I AM GOING TO USE THIS FOREVER :D"

It's great to write something useful, yeah?
Logged
  • My Myspace?
Re: I made a database class of sorts
« Reply #8 on: October 16, 2008, 02:21:39 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
haha, yea.  After 3 years of programming in this god for saken language, you think i would have spat out something useful before this lmao.
Logged



i love big weenies and i cannot lie
Re: I made a database class of sorts
« Reply #9 on: October 16, 2008, 05:38:01 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 256
I took a peek at it, and I'm pretty sure that technically qualifies as a vector.

You're also going to run into some issues if something like this arises:

Code: [Select]
  HVSTDAT<int> one(1);      // Create an HVSTDAT with the int '1' in it. (Everything's fine here.)
  HVSTDAT<int> two(10);     // Create an HVSTDAT with the int '10' in it. (Still fine.)
  one = two;                // Assignment operator. Will do a shallow copy. Bad, you're using dynamic memory.
  HVSTDAT<int> three(one);  // Copy ctor: Shallow copy as well. Also bad.

  // The Assignment operator and copy constructor get written for you.
  // how do you fix this?
  // Don't let anyone touch them!
  // Lets pretend this was your class:
  template <class T>
  class HVSTDAT
  {
  private:
    HVSTDAT();  // You wanted the default constructor disabled.
    HVSTDAT& HVSTDAT(const HVSTDAT&) {} // Disable the copy ctor.
    HVSTDAT& operator=(const HVSTDAT&) {} // Disable the assignment operator too.
  public:
    HVSTDAT(T data);
    ~HVSTDAT();
    //functionszzz.
  };

Two more issue I spotted real quick (That I'm sure you could quickly fix up)
Code: [Select]
HVSTDAT<int> t(1);
t.getData(0); // would work fine.
t.getData(16); // uh oh. getData needs a little error checking :)

t.truncate(); // mainData = new int[0]; ? That doesn't make much sense... does it work?
« Last Edit: October 16, 2008, 05:49:54 pm by nitz »
Logged
  • My Myspace?
Re: I made a database class of sorts
« Reply #10 on: October 17, 2008, 01:06:08 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Alright, so I need to fix up the class a wee bit as what you have...

as for the second part..yea, the truncating stuff works with the array index as 0.  I think I threw the truncate function in the sample somewhere.  I'll add in the error checking as well, I didn't even think of that.  Thanks =D
Logged



i love big weenies and i cannot lie
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.059 seconds with 57 queries.