Sponsored Content
Top Forums Programming does any one know how to solve? Post 302229203 by shamrock on Tuesday 26th of August 2008 11:35:07 AM
Old 08-26-2008
Beg to Differ

Quote:
Originally Posted by redoubtable
Sure. For the situation at hand static cases should only be used if performance really matters.
On the contrary if performance really matters one would go with a dynamic solution in order to minimize the overhead of allocating a very large memory segment and using only a small portion of it. A static solution is not optimized in terms of memory management.

Quote:
Originally Posted by redoubtable
If there is a need to expand the number of entries to an unknown value we should use dynamic algorithms (linked list implementation for example)
Yes a linked list should be used for dynamic cases as it allows searching the database and removing entries from it whereas a sequential list like the one used by the o/p allows only insertions in the form of appends.

Quote:
Originally Posted by redoubtable
Thus confirming that your initial solution can't be used in both static/dynamic cases like I said. If you have a static case that needs expanding sizeof() will not help to determine the number of entries and if you have a dynamic case sizeof() will not help too.
Why would you need to expand a static array. Don't you think that's an oxymoron? If you need to expand an array it becomes dynamic by default. The only case where that solution won't work is the gray scenario you suggested where the number of allocated entries is more than the used ones; as in the case below where the array has 10 entries allocated and only 5 are used. Smilie

Code:
static struct empRec employee[10] =
{
     {"Peter North","4B-208",35400,{10,11,1983}},
     {"John Musa","2B-118",25400,{07,10,1993}},
     {"Paula Jeminova","1A-506",18700,{02,1,1990}},
     {"Patricia Silver","6C-123",52100,{14,21,2000}},
     {"Robert mill","4D-318",42100,{01,19,2008}}
}

Quote:
Originally Posted by redoubtable
Remember that we're talking about an array of structs so either we use linked lists or we would have to malloc() a pointer of pointers to struct empRec.
You won't need double level of indirection...the memory returned by malloc() will be assigned to a pointer to an object of type struct empRec that is a single level of indirection. My earlier post showed that scenario.

Quote:
Originally Posted by redoubtable
Anyway I was just saying that the initial solution you posted will fit best in static cases which don't need expansion because you used sizeof() to calculate the number of entries and that wouldn't be possible if there were more entries in the array struct than those in use.
Imho the only case which it doesn't fit is the gray case you proposed where the number of allocated entries is more than the ones used.
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to solve this

I have to write an script for.. CUST: 123 trans: some contents CUST: 1234 trans: some contents Now wat i have to do is this: CUST:123 akash trans: some contents CUST:1234 akash1 trans: I have been able to add... (3 Replies)
Discussion started by: akashag22
3 Replies

2. Shell Programming and Scripting

Can somebody solve this please

I have to find the files older than 200 days from a path and copy them to some other directory with the current date stamp attached to it. i have written like follows: #!/bin/ksh DSTAMP=$(date +"%y%m%d%H%M") rm $CA_OUT_PATH/ftp_logs/temp touch $CA_OUT_PATH/ftp_logs/temp chmod 777... (1 Reply)
Discussion started by: sreenusola
1 Replies

3. UNIX for Advanced & Expert Users

Can somebody solve this

I have to find the files older than 200 days from a path and copy them to some other directory with the current date stamp attached to it. i have written like follows: #!/bin/ksh DSTAMP=$(date +"%y%m%d%H%M") rm $CA_OUT_PATH/ftp_logs/temp touch $CA_OUT_PATH/ftp_logs/temp chmod 777... (1 Reply)
Discussion started by: sreenusola
1 Replies

4. UNIX for Dummies Questions & Answers

Can somebody solve this

I have to find the files older than 200 days from a path and copy them to some other directory with the current date stamp attached to it. i have written like follows: #!/bin/ksh DSTAMP=$(date +"%y%m%d%H%M") rm $CA_OUT_PATH/ftp_logs/temp touch $CA_OUT_PATH/ftp_logs/temp chmod 777... (13 Replies)
Discussion started by: sreenusola
13 Replies

5. Homework & Coursework Questions

help me to solve it thank you

i thought about to use the commands : wc and sort and mybe more .. i need to write a bash script that recive a list of varuables kaka pele ronaldo beckham zidane messi rivaldo gerrard platini i need the program to print the longest word of the list. word in the output appears on a separate... (1 Reply)
Discussion started by: yairpg
1 Replies

6. UNIX Desktop Questions & Answers

please help me to solve it

i thought about to use the commands : wc and sort cut and mybe more .. i need to write a bash script that recive a list of varuables kaka pele ronaldo beckham zidane messi rivaldo gerrard platini i need the program to print the longest word of the list. word in the output appears on a... (0 Replies)
Discussion started by: yairpg
0 Replies
All times are GMT -4. The time now is 05:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy