Sponsored Content
Top Forums Programming sizeof an array of structure without using 'sizeof' operator Post 302302234 by rvan on Monday 30th of March 2009 12:17:35 PM
Old 03-30-2009
Thank you pshaikh. it exactly gives the sizeof the structure. While executing your first sample piece of code... it is mostly &begin is greater than &end. Here all the local variables begin, end and array[100] gets stored in the stack. When you subtract the begin address and end address and divide it by the sizeof the array it gives the sizeof structure.

But if i try to subtract address of say &array[1] - &array[0] doesn't give the sizeof the array instead it gives 1 always. I just tried printing &array[1] and &array[0] which gives the address. When we subtract the address of begin and end variable it gives the number of bytes occupied between those two and why not in &array[1] - &array[0]. Kindly clarify.


Thanks
 

10 More Discussions You Might Find Interesting

1. Programming

sizeof

we know that sizeof never returns zero when used with structure then why in this case it is returning zero struct foo { char c; }; void main() { struct foo f; cout<<sizeof(f); } i am working on solaris 5.8 isn't the above function should return the size of empty structure (7 Replies)
Discussion started by: ramneek
7 Replies

2. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

3. Programming

Problem in static structure array in C

Hi, I have a following problem in C. I have a function A in which I used to call another function (function B) and pass an array of values through array variable by using below:- foo=functionB(array); In functionB, i used to just return some "values" (e.g return num;) in order to pass... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

4. Programming

How to get the sizeof char pointer

The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function. using namespace std; static void cstrCopy(char *x, const char*y); int main () { char x; const string y = "UNIX FORUM"; cstrCopy(x,y.c_str()); return 0; } void cstrCopy(char *x,... (3 Replies)
Discussion started by: SamRoj
3 Replies

5. Programming

Doubts regarding sizeof() operator

Hi, There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this? int main() { printf("%d\n", sizeof(main)); // Ans: 1 } That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why? ... (5 Replies)
Discussion started by: royalibrahim
5 Replies

6. Programming

sizeof(object) in C++

Hi, I have defined the class and call the sizeof(object to class) to get the size. # include <iostream> # include <iomanip> using namespace std; class sample { private: int i; float j; char k; public: sample() { } (2 Replies)
Discussion started by: ramkrix
2 Replies

7. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

8. Programming

C Data Structure to represent a Sparse Array

Which data structure will be most appropriate to represent a sparse array? (1 Reply)
Discussion started by: rupeshkp728
1 Replies

9. Shell Programming and Scripting

Sizeof a file from directory path in perl

Hai how to find size of a file?? ex : /home/kiran/pdk/sample/calibre this is a path In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies

10. Programming

Compiler/Runtime uses of sizeof

Ignoring other considerations for a moment and in general ... Would there be a difference in result (dot oh or execution) of: A. strncpy( a, b, sizeof(a) ); vs. B. c = sizeof(a); strncpy( a, b, c ); My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies
meminfo(2)							   System Calls 							meminfo(2)

NAME
meminfo - provide information about memory SYNOPSIS
#include <sys/types.h> #include <sys/mman.h> int meminfo(const uint64_t inaddr[], int addr_count, const uint_t info_req[], int info_count, uint64_t outdata[], uint_t validity[]); PARAMETERS
inaddr array of input addresses; the maximum number of addresses that can be processed for each call is MAX_MEMINFO_CNT addr_count number of addresses info_req array of types of information requested info_count number of pieces of information requested for each address in inaddr outdata array into which results are placed; array size must be the product of info_count and addr_count validity array of size addr_count containing bitwise result codes; 0th bit evaluates validity of corresponding input address, 1st bit validity of response to first member of info_req, and so on DESCRIPTION
The meminfo() function provides information about virtual and physical memory particular to the calling process. The user or developer of performance utilities can use this information to analyze system memory allocations and develop a better understanding of the factors affecting application performance. The caller of meminfo() can obtain the following types of information about both virtual and physical memory. MEMINFO_VPHYSICAL physical address corresponding to virtual address MEMINFO_VLGRP locality group of physical page corresponding to virtual address MEMINFO_VPAGESIZE size of physical page corresponding to virtual address MEMINFO_VREPLCNT number of replicated physical pages corresponding to specified virtual address MEMINFO_VREPL | n nth physical replica of specified virtual address MEMINFO_VREPL_LGRP | n lgrp of nth physical replica of specified virtual address MEMINFO_PLGRP locality group of specified physical address RETURN VALUES
Upon successful completion meminfo() returns 0. Otherwise -1 is returned and errno is set to indicate the error. ERRORS
The meminfo() function will fail if: EFAULT The area pointed to by outdata or validity could not be written, or the data pointed to by info_req or inaddr could not be read. EINVAL The value of info_count is greater than 31 or less than 1, or the value of addr_count is less than 1. EXAMPLES
Example 1: Print physical pages and page sizes corresponding to a set of virtual addresses. The following example prints the physical pages and page sizes corresponding to a set of virtual addresses. void print_info(void **addrvec, int how_many) { static const uint_t info[] = { MEMINFO_VPHYSICAL, MEMINFO_VPAGESIZE }; int info_num = sizeof (info) / sizeof (info[0]); int i; uint64_t *inaddr = alloca(sizeof (uint64_t) * how_many); uint64_t *outdata = alloca(sizeof (uint64_t) * how_many * info_num); uint_t *validity = alloca(sizeof (uint_t) * how_many); for (i = 0; i < how_many; i++) inaddr[i] = (uint64_t)addrvec[i]; if (meminfo(inaddr, how_many, info, info_num, outdata, validity) < 0) { perror("meminfo"); return; } for (i = 0; i < how_many; i++) { if ((validity[i] & 1) == 0) printf("address 0x%llx not part of address space ", inaddr[i]); else if ((validity[i] & 2) == 0) printf("address 0x%llx has no physical page " "associated with it ", inaddr[i]); else { char buff[80]; if ((validity[i] & 4) == 0) strcpy(buff, "<Unknown>"); else sprintf(buff, "%lld", outdata[i * info_num + 1]); printf("address 0x%llx is backed by physical " "page 0x%llx of size %s ", inaddr[i], outdata[i * info_num], buff); } } } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
memcntl(2), mmap(2), gethomelgroup(3C), getpagesize(3C), madvise(3C), sysconf(3C), attributes(5) SunOS 5.10 21 Feb 2003 meminfo(2)
All times are GMT -4. The time now is 10:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy