![]() |
| | #16 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| (I really don't know what I'm talking about here, but I could see that happening.) [edit] Regarding bithub's post: Wow, my guess was right! [/edit]Anyway, you *really* shouldn't allocate 1GB just because you can. Re-think your algorithm, use realloc(), and only if it's too slow go with another solution. One thing you could do is to simulate lazy allocation in your own program. Let's say you have a data structure like this: Code: struct data_t {
char data[20];
};
Code: struct data_t *lookup(struct index_t where); Of course, that's really just a spare matrix in disguise, so you should read up more on how they can be implemented . . . the only type of sparse matrix implementation I've ever done was in a program of mine called planedist. You can download it here: http://dwks.theprogrammingsite.com/m...anedist.tar.gz [I believe you need SDL and SDL_gfx to compile it, which you can get here: Simple DirectMedia Layer] explanation.txt in that archive describes the algorithm. Anyway, you could use something like that for your own code if you wanted to. Keep in mind that I know absolutely nothing about this subject and came up with that algorithm by myself after a few hours of puzzlement. No idea if it's any good . . . .
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #17 |
| Kung Fu Kitty Join Date: Oct 2008 Location: Montreal, Canada
Posts: 107
| I see. Usually, eh? Well, I guess there's not much point in trying to program for lazy allocation. In any case, my hopes for calloc() are shattered, because it clearly doesn't generally do the lazy allocation I thought it was for ![]() Thanks |
| Angus is offline | |
![]() |
| Tags |
| calloc, lazy allocation, malloc |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic array Allocation | deepak_j | C Programming | 3 | 08-17-2009 07:18 AM |
| dynamic allocation from 1 instead of zero | cfdprogrammer | C Programming | 27 | 04-28-2009 08:21 AM |
| pointer to array with dynamic allocation | cfdprogrammer | C Programming | 22 | 04-07-2009 09:56 AM |
| redundant allocation | George2 | C++ Programming | 22 | 03-06-2008 06:43 PM |
| Dynamic memory allocation. | HAssan | C Programming | 3 | 09-07-2006 05:04 PM |