| | |
efficient array update
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
You're developing a realtime application, and don't know how to add values to elements of an array?????
Pull my other leg: it'll play a tune for you.
What is the criterion by which you would describe a method as "best"? If you are truly designing a realtime application, you will realise the significance of that question.
Pull my other leg: it'll play a tune for you.
What is the criterion by which you would describe a method as "best"? If you are truly designing a realtime application, you will realise the significance of that question.
If you want to set all elements to 0 then you can use memset(). Microsoft compilers implement that function in assembly because the chip has an instruction that will do it, and that is about as efficient as you can get. I don't know how other compilers implement it.
Also use the = {0} when declaring the array.
Also use the = {0} when declaring the array.
int myarray[255] = {0}; Last edited by Ancient Dragon; Jan 14th, 2009 at 9:48 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
•
•
•
•
I'll wager a bet that he means "The most efficient" means by which to add a value to all items in an array.

He probably also needs to specify the type of array elements. Adding a value to elements of an array of strings might conceivably require a technique that differs from adding a value to elements of an array of int.
Incidentally, I despise irrelevant questions that put carts before horses.
•
•
Join Date: Jan 2009
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
You're developing a realtime application, and don't know how to add values to elements of an array?????
Pull my other leg: it'll play a tune for you.
What is the criterion by which you would describe a method as "best"? If you are truly designing a realtime application, you will realise the significance of that question.
Thank you for your help.
Last edited by a10m84; Jan 15th, 2009 at 5:21 am.
•
•
Join Date: Jan 2009
Posts: 46
Reputation:
Solved Threads: 7
[] operator is the best to add values to an array, I think. Applicable only if you know the index in advance.
If you have to search in runtime for the position to which we can add a value, it will have a complexity of O(n). In that situation, if possible, use stl map.
If you have to search in runtime for the position to which we can add a value, it will have a complexity of O(n). In that situation, if possible, use stl map.
> I know how to add values to an array. I am developing an application
> with RTAI, comedi and Qwt (plotting in realtime).
Oh please tell me you've used a profiler to work out where the real hot spots are, and not just picked random lines of code out based on guesswork.
Dickering about with an array of a few 1000 entries is nothing to the cost of plotting all those millions of pixels in your nice glossy user interface.
You just can't say "draw it" and hope that it takes zero time, because it won't. How you draw it will have a much larger impact on performance than what you're suggesting.
> with RTAI, comedi and Qwt (plotting in realtime).
Oh please tell me you've used a profiler to work out where the real hot spots are, and not just picked random lines of code out based on guesswork.
Dickering about with an array of a few 1000 entries is nothing to the cost of plotting all those millions of pixels in your nice glossy user interface.
You just can't say "draw it" and hope that it takes zero time, because it won't. How you draw it will have a much larger impact on performance than what you're suggesting.
![]() |
Similar Threads
- Populating form with existing MySQL data (PHP)
- Need help starting (C++)
- checkbox or radio button value cant keep during recordset paging function (ASP)
- ARRAY help (Pascal and Delphi)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Help for a Biologist (Java)
Other Threads in the C++ Forum
- Previous Thread: About Monthly Calendar
- Next Thread: using c++ file handling write a salary slip
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






