Sponsored Content
Top Forums Programming Dynamically allocated structures in C Post 302335238 by Corona688 on Friday 17th of July 2009 07:38:32 PM
Old 07-17-2009
Did you mean:

for(i=0;i<N;i++) grid[i].neigh = malloc(sizeof(int)*M);

If so, I don't see anything fundamentally wrong with it. The newly-allocated memory is not guaranteed to be blank, however:

Code:
for(i=0;i<N;i++)
{
  grid[i].neigh = malloc(sizeof(int)*M);
  memset(grid[i].neigh, 0, sizeof(int) * M);
}

 

10 More Discussions You Might Find Interesting

1. Programming

reallocating structures dynamically in functions

I've recently started using structures, but I am having problems in allocating the structure dynamically. In the code below if i allocate the structure in the main program it works fine, and i get the expected output. However if i use the function rper below to increase the size of the structure i... (0 Replies)
Discussion started by: cezaryn
0 Replies

2. Programming

pointer to structures

Dear friends I have a bit basic doubts in pointers and the structures inter relationships. the first one. static struct apvt { int dead; int pending; int abouttograb; }*agents=NULL; what agents pointer is... (1 Reply)
Discussion started by: tech_voip
1 Replies

3. Programming

Programming using Structures

Hi All, I was given a format of a file, and was asked to write a program which displays the data contained in the file in that purticular format. Its all so confusing. Please find the example of the format as well the code I have written in the attachment. I hope any one of u guyz can... (0 Replies)
Discussion started by: jazz
0 Replies

4. Solaris

Memory allocated

Hi, How to find out what is the maximum memory allocated to TOMCAT server in SunOS 5.8? The Tomcat server crashes down during peak times.... Regards (1 Reply)
Discussion started by: baanprog
1 Replies

5. Linux

about system structures

hello can any1 plz tell me about the system defined structures (like sysinfo) which wil give system and n/w charecteristics (ex: freeram in sysinfo). (1 Reply)
Discussion started by: jeenat
1 Replies

6. Solaris

xntpd[28781]: too many recvbufs allocated

Hi, I have a server that is getting the following alarm a couple times a day: Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) I know this is some sort of NTP related issue but I need to gauge the severity of... (0 Replies)
Discussion started by: BrewDudeBob
0 Replies

7. Solaris

Can be changeed the allocated space

i am working with solaris 9 and my disk usages are # df -k Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 2148263 1902721 202577 91% / /proc 0 0 0 0% /proc mnttab 0 0 0 ... (3 Replies)
Discussion started by: smartgupta
3 Replies

8. Shell Programming and Scripting

Help with variables for filesystems allocated

Hi all, I am interning in a unix department and am very new to programming. I am supposed to write a script that counts the amount of filesystems a server has allocated, and the amount free. This is what I was given to start with: #!/bin/ksh df -m | grep -v ":"|grep -v Free|grep -v "/proc"|... (6 Replies)
Discussion started by: compan023
6 Replies

9. UNIX for Advanced & Expert Users

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

10. Programming

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies
t_alloc(3)						     Library Functions Manual							t_alloc(3)

NAME
t_alloc() - allocate transport function library structure SYNOPSIS
-- or -- DESCRIPTION
The function dynamically allocates memory for the various transport function argument structures as specified below. This function will allocate memory for the specified structure and will also allocate memory for buffers referenced by the structure. The structure to allocate is specified by struct_type and must be one of the following: T_BIND struct t_bind T_CALL struct t_call T_DIS struct t_discon T_INFO struct t_info T_OPTMGMT struct t_optmgmt T_UDERROR struct t_uderr T_UNITDATA struct t_unitdata where each of these structures may subsequently be used as an argument to one or more transport functions. Each of the above structures, except T_INFO, contains at least one field of type For each field of this type, the user may specify that the buffer for that field should be allocated as well. The length of the buffer allocated will be equal to or greater than the appropriate size returned in the info argument of or The relevant fields of the info argument are described in the following list. The fields argument specifies which buffer to allocate, where the argument is the bitwise-OR of any of the following: The addr field of the or structures. The opt field of the or structures. The udata field of the or structures. All relevant fields of the given structure. Fields which are not supported by e transport provider specified by fd will not be allocated (info values are <= 0). For each field specified in fields, will allocate memory for the buffer associated with the field, and initialize the len field to zero and the buf pointer and maxlen field accordingly. Since the length of the buffer allocated will be based on the same size information that is returned to the user on or fd must refer to the transport endpoint through which the newly allocated structure will be passed. In this way the appropriate size information can be accessed. If the size value associated with any specified field is -1 or -2 ( see t_open(3) or t_getinfo(3)), will be unable to determine the size of the buffer to allocate and will fail, setting to and to For any field not specified in fields, buf will be set to a null pointer and maxlen will be set to zero. Use of to allocate structures will help ensure the compatibility of user programs with future releases of the transport interface func- tions. Valid States All, apart from Fork Safety is not fork-safe. RETURN VALUE
Upon successful completion, returns a pointer to the newly allocated structure. On failure, a null pointer is returned. ERRORS
On failure, is set to one of the following: fd, the specified endpoint identifier, does not refer to a transport endpoint. A system error has occurred during execution of this function. (XTI only) This error indicates that a communication problem has been detected between XTI and the transport provider for which there is no suitable XTI Unsupported struct_type requested. This can include a request for a structure type which is inconsistent with the transport provider type specified, that is, connection-oriented or connectionless. SEE ALSO
t_free(3), t_getinfo(3), t_open(3), thread_safety(5). STANDARDS CONFORMANCE
t_alloc(3)
All times are GMT -4. The time now is 03:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy