On Sun, 2007-09-30 at 18:12 +0200, Michael Blizek wrote:
> Hi!
>
> I'm assuming you're working in userspace, since the memory allocation
Which leads to the obvious question: What's the relevance of the
question to the Linux kernel?
> function in the kernel is kmalloc.
>
> On Sat, 2007-09-29 at 16:49 -0700, Irfan Ahmed wrote:
> > I need four dimensional array like
> > double a[256][256][256][256];
> >
> >
> > but the size is too big to use an array.
Why?
> That's 32 GB memory! Are you *really* sure you want to do this? It would
> require a 64 bit system and "some" ram/swap space if you access the
> array. You have to do this on the *heap* not on the stack and have to be
> careful not to produce an integer overflow.
>
> > If I use only pointer like
> > double ****a;
> >
> > to allocate this memory, I have to run 3 loops to allocate
> > memory ..which takes lots of time.
>
> Because of 256^3 = ~17 million system calls...
And the result will use even more than 32GB because you need also space
for the pointers for the last 3 dimensions.
> > I was thinking to use *a[256][256][256]
> > Can I use this ...and if yes how I can allocate the memory for
> > this...?
---- snip ----
a = malloc(sizeof(double) * 256 * 256 * 256).
---- snip ----
But this is only 3-dimensional and (in terms of RAM usage) equivalent to
declaring
---- snip ----
double a[256][256][256];
---- snip ----
and using it.
What are you trying to accomplish?
> You can do this, but it would be a 3 dimensional array of pointers,
> which is probably not what you want. Why not just allocate a memory and
> "cast" the pointer to an array?
Just assign/use it, no cast necessary. In fact, casting to quiet the
compiler hides probably serious errors and problems.
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ