473,786 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to Allocate more space than size_t

hi folks
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
can you tell me which library/system call to use..
Plz consider that all the physical hardware req for such an operation
is available... i know this sounds crazy... but just help me out here
....
Thanks in Advance
Rahul

Nov 14 '06 #1
20 2645

i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to

consequtive bytes and dynamic allocation ???

Nov 14 '06 #2

ra************* ******@gmail.co m wrote:
hi folks
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
can you tell me which library/system call to use..
This is probably wandering into "Off-topic for comp.lang.c" - there's
no way in the standard language.

You'd have to delve into the O/S to do this, if it is possible at all.
On un*x-like systems the "brk()" or "sbrk()" calls are probably
relevant, or the memory-mapping calls (mmap()) but...

Are you actually able to deal with more memory than size_t can denote?
You will be limited, one way or another by issues such as
addressability. . If you are working on a 32-bit O/S, then you cannot
(AFAIK) have more than 4Gb of address space for a process, for example.
Plz consider that all the physical hardware req for such an operation
is available...
But if the O/S can't access more than size_t can denote, that's no help
at all..
i know this sounds crazy... but just help me out here
You probably need to give us more information, but we'll probably point
you at a newsgroup relating to your platform...

Nov 14 '06 #3
"ra************ *******@gmail.c om" <ra************ *******@gmail.c om>
wrote:
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
can you tell me which library/system call to use..
There isn't any. If you need more memory than can be specified in a
size_t, ISO C gives you no way to do so. Ideally, this shouldn't even be
possible; your implementation should make size_t large enough to cater
for every possible memory block size.

Richard
Nov 14 '06 #4
ra************* ******@gmail.co m wrote:
hi folks
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
can you tell me which library/system call to use..
Plz consider that all the physical hardware req for such an operation
is available... i know this sounds crazy... but just help me out here
...
This is not possible using strictly standard C. The type size_t is
specifically meant to store the sizes of objects in a C program and it
should be possible to contain within a size_t object, the size of the
largest possible object guaranteed under standard C.

Generally, one would expect size_t to be equivalent to the largest
unsigned type, under most implementations , though you cannot assume
this. For example, on my implementation here, size_t is a typedef for
unsigned int, even though unsigned long long int, a much larger
unsigned type, is also available.

Anyway, returning to your question, the short answer is that you'll
have to use implementation specific extensions or, more likely, OS
specific system calls and their corresponding types. Asking in a group
for your system might get more helpful responses.

Nov 14 '06 #5
sa*****@yahoo.c o.in wrote:
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to


consequtive bytes and dynamic allocation ???
Why not? As far as a conforming C program is concerned, the component
bytes of a single dynamically allocated object are consecutive, though
that may not be the case as far as the layout of the object on physical
memory is concerned.

Nov 14 '06 #6
Why not? As far as a conforming C program is concerned, the component
bytes of a single dynamically allocated object are consecutive, though
that may not be the case as far as the layout of the object on physical
memory is concerned.
I have never seen a requirement to allocate memory dynamically and
to expect that to be in consecutive locations... may be the OP should
explain the actual reason as to why he needs this, if he can...

Nov 14 '06 #7
sa*****@yahoo.c o.in wrote:
>Why not? As far as a conforming C program is concerned, the component
bytes of a single dynamically allocated object are consecutive, though
that may not be the case as far as the layout of the object on physical
memory is concerned.

I have never seen a requirement to allocate memory dynamically and
to expect that to be in consecutive locations... may be the OP should
explain the actual reason as to why he needs this, if he can...
The OP seems to be talking about resizing, (enlarging), the allocation
for a single object with a call to realloc(). The bytes of a single
dynamically allocated object in C are consecutive to the program.

If you're talking about the layout of two or more dynamic objects then
yes, they need not be consecutive.

Nov 14 '06 #8
<ra************ *******@gmail.c omwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
hi folks
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
can you tell me which library/system call to use..
size_t is able to hold the size of the largest object you can allocate
with malloc() or realloc() by definition. That means that, within the
realm of Standard C, there is no way to allocate an object larger than
SIZE_MAX.

Your OS may have mechanisms to allocate larger objects; you'll need to
ask about those in an OS-specific newsgroup.
Plz consider that all the physical hardware req for such an operation
is available... i know this sounds crazy... but just help me out here
Note that any sane implementation will define size_t such that it can
handle anything the system is capable of. It is unlikely that your OS
does, in fact, have something better, because that's what the C
implementors would have used if it were available.

For example, on x86 with PAE, your machine may have 36 bits of physical
memory, but it's impossible to access more than 32 bits of address space
from a single program, so size_t will be 32 bits. Ditto for an 32-bit
program running inside a 64-bit OS; the OS can hand out a different 4GB
address space to each program, but no single program can use more than
4GB on its own. A 64-bit program on the same OS would have a 64-bit
size_t.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

--
Posted via a free Usenet account from http://www.teranews.com

Nov 14 '06 #9

ra************* ******@gmail.co m wrote:
hi folks
i have a peculiar problem. i have to allocate more than size_t
consequtive bytes on a system . after i do a malloc .. i am unable to
do a realloc because it takes size_t as a new size and not as an
incremental size..
As I and others have pointed out, you can't do this in Standard C and
it's very likely that you can't do it using non-standard techniques
either.

Why not describe what you are trying to achieve with this huge memory
allocation and let us suggest alternative ways of meeting your goal?

Nov 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
16175
by: Grumble | last post by:
Hello all, I want to read lines from a text file, where each line has the following syntax: token1:token2:token3 There could be white space between tokens and ':'
5
2484
by: lixiaoyao | last post by:
hi all I use matrix & vector function to allocate the space myself in c, typedef struct matrix_array newdata; struct matrix_array{ float **sy,*sxx; }; newdata ndata;//new data struct ndata.sy=matrix(1,nvar,1,nstep); ndata.sxx=vector(1,nstep);
2
2870
by: aj902 | last post by:
Hello , I am trying to create a program where all detail, http://www.albany.edu/~csi333/projects.htm
12
5638
by: gc | last post by:
I am writing a function that given nx1 vector a and a nx1 b solves a system of equations f(a,c)=b for a nx1 c. While writing the function: 1] Should I allocate the memory for c within the function and return the allocated memory? something that leads to double *solve(const double *a,const double *b,int n) { double *c;
21
3226
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
2
3451
by: xhunga | last post by:
I have try a new version of my work. I have put the sizes of the matrix into the matrix. A = number of rows A = number of columns The first element of the matrix is A instead of A. You can not use the row 0, and the column 0.
43
4942
by: Frodo Baggins | last post by:
Hi all, We are using strcpy to copy strings in our app. This gave us problems when the destination buffer is not large enough. As a workaround, we wanted to replace calls to strcpy with strncpy. That is, replace calls to strcpy with say, my_strcpy(dest,src) which will internally find the destination buffer length. For this we need to know the destination buffer size. For statically allocated strings sizeof is returning the length of the...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.