473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Size of Allocated Memory

I have a function that returns a int pointer to a allocated memory.
How I know the size of this allocated memory?

Compiler = gcc
Ex.:

int main(void)
{
int *pointer;
pointer = fakefunc();

/* How I know the size of allocated memory?? */

return 0;
}
Nov 14 '05 #1
3 6871
mandark_br <ma*****@rockpesado.com.br> wrote:
I have a function that returns a int pointer to a allocated memory.
How I know the size of this allocated memory? int main(void)
{
int *pointer;
pointer = fakefunc(); /* How I know the size of allocated memory?? */
By simply storing it when you allocate the memory and then
returning it from fakefunc() together with the pointer.
There's no standard function that would give you that
information just from the pointer.
Compiler = gcc


The compiler is completely irrelevant. If you're looking
for a non-portable solution you will have to check if the
libc you're using has an extension for doing that because
the libc is where malloc() and friends are defined.

Regards. Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
mandark_br wrote:

I have a function that returns a int pointer to a allocated memory.
How I know the size of this allocated memory?


This is Question 7.27 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

.... and you may want to look at Question 7.26 also. You
won't like the answers, though.

--
Er*********@sun.com
Nov 14 '05 #3
mandark_br <ma*****@rockpesado.com.br> wrote:
I have a function that returns a int pointer to a allocated memory.
How I know the size of this allocated memory? Compiler = gcc
Ex.: int main(void)
{
int *pointer;
pointer = fakefunc(); /* How I know the size of allocated memory?? */ return 0;
}


You can't, and you shouldn't need to. It is your responsibility to keep
track of how much memory 'fakefunc' allocates. If you can't do that in
your context, then show us a more concrete example.

--
Alex Monjushko (mo*******@hotmail.com)
Nov 14 '05 #4

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

Similar topics

7
by: serikas | last post by:
Is there a way to get aligned dynamically allocated memory? (provided that the requested memory size is a power of 2.) For example, if I request 128 bytes of memory, can I implement an allocator...
34
by: Andrew | last post by:
Is there anyway to test if a pointer points to allocated memory or not? For example if I have a pointer such as char *p is there a standard way to test whether an assignment such as the following...
0
by: menkaur | last post by:
Is there eny way to get the memory size allocated with new (like GlobalSize for GlobalAlloc) ?
19
by: pinkfloydhomer | last post by:
Please read the example below. I'm sorry I couldn't make it smaller, but it is pretty simple. When client code is calling newThingy(), it is similar to malloc: the client gets a pointer to a...
74
by: ballpointpenthief | last post by:
If I have malloc()'ed a pointer and want to read from it as if it were an array, I need to know that I won't be reading past the last index. If this is a pointer to a pointer, a common technique...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
3
by: Jinkuzo | last post by:
Have been working on this project for a week, unfortunately missed the lesson on it and have been struggling to figure it out. These are the instructions and the point at which I'm up to. ...
8
Hackles
by: Hackles | last post by:
Hello, Is it possible to retrieve the size of allocated memory from a pointer (more specifically, a pointer returned my malloc/realloc). This question may have already been asked countless times....
5
by: Paul | last post by:
hi, there, I was asked such a question: how to determine the size of memory of the int pointer pointed? for example int GetTheSizeofMemory(int *buffer) { int size; //enter your code here,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.