Skip to main content
gamedev.net
🔒 Locked

array

Started by Tiger99 Mar 10, 2003 at 10:07 PM 8 replies 1.4k views
Original Post
Tiger99
Tiger99
Hello I am just wondering can I not specify the size of an array at declaration. Then increase the size as I start using it? eg. enum data{ int array[]; } function(){ enum data data1; data1->array[0] = "c"; data1->array[1] = "d"; ..... } Thanks
RhoneRanger
RhoneRanger
look into std::vector
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
TalonSnow
TalonSnow
i personaly like making my own class for it as a dynamically allocated array. I like doing this as I can make it run just as fast as Vectors if not faster, designed specifically for my needs. Also it will have ALOT less overhead.

If you want a very simple sample sent to you via email or msn or whatever just give me a hollar at my unfinished website or email me.
<=- Talon -=>
Tiger99
Tiger99
Hello
Since I am writing my own OS, I can''t use any C libraries. So how could I go about making my own vector?

Thanks
MOVSW
MOVSW
Simple dynamic array

int *anysize;
int entersize;

printf("Size: ");
scanf("%i",&entersize);

anysize=new int[entersize];

anysize[(entersize/2)]=8888;

delete [] anysize;
anysize=0;

For unlimited sized data structures you can either use linked lists or Vector class.

[edited by - MOVSW on March 10, 2003 12:27:55 AM]
Qw3r7yU10p!
Qw3r7yU10p!
quote:
Original post by TalonSnow
i personaly like making my own class for it as a dynamically allocated array. I like doing this as I can make it run just as fast as Vectors if not faster, designed specifically for my needs. Also it will have ALOT less overhead.


What overhead are you talking about with std::vector? How did you make it faster? Do you have the code and timing rig available?

I think maybe you haven''t tested properly.
TalonSnow
TalonSnow
Its overhead is in calling the functions used in std, where as most applications of vectors dont need the power of vectors and can just use dynamic arrays or even dynamic linked lists, especially when embedded in the code.
<=- Talon -=>
afterburn
afterburn
will enum''s are constants. They will not help you.

I beleive that you are looking for struct.

Data *Data(int Size){
Data *dt = new Data[Size];
return dt;
}

As for the OS buddy good luck. Not that bad if you know ASM and Get all of the docs from vendors for hardware support. not easy to remember how to draw to a screen.

dx mov,1,eax; #gets badd at this point.

Not sure if that is valid syntax but from what I remember of ASM.

Got to remember all those damned meaningless registers... Not to forget the interupts and IRQ''s....... You would have to write from scratch all the low level drawing to a screen. Keyboard and mouse support? if you are that interested in an OS go download linux.

--What are you nutz?I have nothing to say to your unevolved little brain. The more I say gives you more weapons to ask stupid questions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.