C dislikes my char dictionary[300000][30] why?

Pathogen

Newbie
Joined
Aug 22, 2003
Messages
54
Reaction score
0
The title says it all, im trying to load a dictionary into a 2D array so i can search it fast, anyways, the compiler chokes on this bit of code

char dict[300000][10];

Is this when you're supposed to use malloc? i've never used that command and im reading up on it now but if a benevolent coder wants to lend a helping hand in the season of giving that would be greatly appreciated, if you guys want me to post all the source here thats doable, i wont unless you guys really need it

Thanks
:cheers:
 
I get a feeling the compiler would still choke if you used malloc. Not to mention the fact that you'd be allocating 3 megs of memory. Post your compiler error log so we can get a better idea of what's going wrong.

P.S. Malloc is ugly... use C++....
 
malloc is ugly.

I think the only reason the compiler is choking is because 3MB is too much for the stack.

Allocating 3MB using malloc (or new) should work perfectly fine.
 
henrym said:
I think the only reason the compiler is choking is because 3MB is too much for the stack.

Allocating 3MB using malloc (or new) should work perfectly fine.
I'll second that for now* :)

*until disproven
 
FragBait0 said:
I'll second that for now* :)

*until disproven
Heh, yeah.

Pathogen: it would be best if you could post the actual compiler error(s), until then we're just guessing.
 
Yeah, but I suppose 3mb on the heap wouldn't bother it. So since you're using C, malloc away! But really, free when you're done, memory leaks can get ugly pretty fast.
 
Hurrah for memory leaks!

edit: and henrym is right
 
... Don't take this the wrong way, but you need to take a data structures class... now. Don't get me wrong using brute force does work on occasion, but wouldn't a far more elegant solution be to subdivide the dictionary ? I mean honestly the whole thing is begging for a search tree of some sort, hell you can make a balanced AVL tree exceedingly easily as you have a static number of possible entries (26 characters, or if you want to make a generic system less than 255 for standard ASCII). Oh well not my project, if you are going to use dynamic memory allocation you should probably be using calloc. Though you may still run into trouble unless you are building a win_32 application.
 
Back
Top