473,662 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine the size of dynamical arrays?

Hello,

after i've read this post, i tried it myself and it works.
http://groups.google.com/groups?hl=e...oogle%2BSearch
But I've the following problem: I can't determine the size of the
dynamical generated array through a predefined function like sizeof().
Can anybody explain, how to get the reserved memorysize?

Thanks,
Frater
Nov 13 '05 #1
4 3529
FraterQ wrote:
Hello,

after i've read this post, i tried it myself and it works.
http://groups.google.com/groups?hl=e...oogle%2BSearch
But I've the following problem: I can't determine the size of the
dynamical generated array through a predefined function like sizeof().
Can anybody explain, how to get the reserved memorysize?


"dynamical" ???

This question is asked far too often. Go read the FAQ.

Tom

Nov 13 '05 #2
FraterQ wrote:

<snip>
But I've the following problem: I can't determine the size of the
dynamical generated array through a predefined function like sizeof().
Can anybody explain, how to get the reserved memorysize?


When you allocate the memory, you know how much you're allocating.

Don't Forget.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #3
In 'comp.lang.c', ts@ssb-multimedia.de (FraterQ) wrote:
Hello,

after i've read this post, i tried it myself and it works.
http://groups.google.com/groups?hl=e...&threadm=9jjh9
m%247bb%242%40o ravannahka.hels inki.fi&rnum=1& prev=/groups%3Fhl%3De n%26lr%
3D%26ie%3DUTF-8%26oe%3Dutf-8%26q%3Dresize% 2Barray%2Bc%2Br ealloc%26btnG%3 D
Google%2BSearch But I've the following problem: I can't determine the
size of the dynamical generated array through a predefined function like
sizeof(). Can anybody explain, how to get the reserved memorysize?


Ask the one who has allocated the memory block to keep the size in some
memory. A common tip is the following :

typedef struct
{
int *a; /* dynamic array of int */
size_t n;
}
buf_s;

buf_s buf;

buf_create (&buf, 123);

with

int buf_create (buf_s * this, size_t n)
{
err = 1;

if (this)
{
this->a = NULL;
this->n = 0;

{
int *p = malloc (sizeof *p * n); /* <stdlib.h> */

if (p)
{
this->a = p;
this->n = n;
err = 0;
}
}
}
return err;
}
--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #4
ts@ssb-multimedia.de (FraterQ) wrote (02 Jul 2003) in
news:56******** *************** ***@posting.goo gle.com / comp.lang.c:
Hello,

after i've read this post, i tried it myself and it works.
http://groups.google.com/groups?hl=e...=utf-8&threadm
=9jjh9m%247bb%2 42%40oravannahk a.helsinki.fi&r num=1&prev=/groups%3Fh
l%3Den%26lr%3D% 26ie%3DUTF-8%26oe%3Dutf-8%26q%3Dresize% 2Barray%2Bc%2
Brealloc%26btnG %3DGoogle%2BSea rch But I've the following problem:
I can't determine the size of the dynamical generated array
through a predefined function like sizeof(). Can anybody explain,
how to get the reserved memorysize?


Remember it, for goodness' sake! You can't dynamically create
without having the size information; why do you throw away what you
already know?
--
Martin Ambuhl
Returning soon to the
Fourth Largest City in America
Nov 13 '05 #5

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

Similar topics

2
5096
by: Jason | last post by:
I have a number of arrays that are populated with database values. I need to determine which array has the highest ubound out of all the arrays. The array size will always change based on the database record. Therefore, I need to be able to throw the arrays into a function that will automatically determine the highest ubound array. I was wondering if anyone might have a clean function that can do this. I have created a function that...
5
1232
by: Sune | last post by:
Hi, I need to replace some dynamical content away from a text, only static thing is that it starts with <!-- Start dynamic --> and ends with <!-- End dynamic -->. How do i dynamical remove these two tags and all the content between them? Thank you very much. -- Regards,
11
6748
by: Linny | last post by:
Hi, I need some help in declaring an array of pointers to array of a certain fixed size. I want the pointers to point to arrays of fixed size only (should not work for variable sized arrays of the same type). eg: int arr1;//Array of 20 ints int arr2; int arr3; ............
14
7273
by: Christopher Benson-Manica | last post by:
From FAQ 6.13: int arr; int (*a)=arr; /* legal, but useless */ printf( "%d\n", a ); /* error, bounds of a unspecified */ Are there non-contrived situations where an array of unspecified bounds is useful?
31
3704
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the malloc package to find out how big an allocated block is". ( Question 7.27) Is there somwhere explained why - because it would seem to me, that free()
14
2498
by: Roman Mashak | last post by:
Hello, All! Is there an easy way to determine that array e.g. int X contains ordered items (for example, ascending), except running loop with comparison of items? It would be good to provide me with some useful link :) Thanks!
16
3414
by: Jm | last post by:
Hi All Is it possible to determine who is logged onto a machine from inside a service using code in vb.net ? I have found some code that seems to work under vb6, but doesnt under .NET ? Any help is greatly appreciated Thanks
13
3643
by: coinjo | last post by:
Is there any function to determine the length of an integer string?
36
3795
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used to read text or handle arrays of arbitrary length. I don't have the expertise in C of many folks here so I feel like I'm offering a small furry animal for sacrifice to a big armour plated one... but will offer it anyway. Please do suggest...
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8633
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
7368
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...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.