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.
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.
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)
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)
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)
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)
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)
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)