Click here to Skip to main content
15,916,449 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# serial port Pin
aniarun15-Dec-09 18:52
aniarun15-Dec-09 18:52 
GeneralRe: C# serial port Pin
aniarun16-Dec-09 13:18
aniarun16-Dec-09 13:18 
QuestionTopic For Imagine Cup Pin
mwaqas199014-Dec-09 12:38
mwaqas199014-Dec-09 12:38 
AnswerRe: Topic For Imagine Cup Pin
Richard MacCutchan14-Dec-09 23:02
mveRichard MacCutchan14-Dec-09 23:02 
GeneralRe: Topic For Imagine Cup Pin
mwaqas199015-Dec-09 12:19
mwaqas199015-Dec-09 12:19 
QuestionData structure advice Pin
robertwaw14-Dec-09 10:45
robertwaw14-Dec-09 10:45 
AnswerRe: Data structure advice Pin
Dr.Walt Fair, PE14-Dec-09 11:43
professionalDr.Walt Fair, PE14-Dec-09 11:43 
AnswerRe: Data structure advice [modified] Pin
Luc Pattyn14-Dec-09 11:46
sitebuilderLuc Pattyn14-Dec-09 11:46 
Hi,

if I understand you correctly you have an object per pixel, holding grayscale, x, y, and some state. That is a lot of data, and a sure way to spend lots of memory and time. .NET will need some 32 bytes per object, so a megapixel image of yours will consume some 40MB of memory of which 80% is irrelevant to your app (I'm assuming shorts for grayscale, x, y, state). These pixel objects will be spread around in your app's memory, and the garbage collector will eventually have to watch over them and collect them when no longer needed; that will take some doing.

So I am completely against the idea of turning every pixel into an object.

I also am not sure why a pixel needs to store its location, I've never done that.

I tend to keep monochrome pixels in a one-dimensional array, so I can easily move to its neighbours (by adding +1, -1, +WIDTH, or -WIDTH to the array index, or pointer). A second array could keep the state. That would result in only 4 bytes/pixel, one tenth of the pixel=object approach; and pixels would be adjacent in memory making your app take full advantage of the processor caches.

Another tip is this: having state, you could make the arrays a bit larger, effectively adding a boarder to the image, then store a special value in the state array for those border "pixels". That may be sufficient to avoid all border tests, as you now can move from a pixel to its neighbour, and from an edge pixel to a border pixel, without falling of the image.

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


modified on Monday, December 14, 2009 6:45 PM

QuestionService does not start [modified] Pin
Jordanwb14-Dec-09 10:45
Jordanwb14-Dec-09 10:45 
AnswerRe: Service does not start Pin
Migounette14-Dec-09 11:43
Migounette14-Dec-09 11:43 
GeneralRe: Service does not start Pin
Jordanwb14-Dec-09 12:12
Jordanwb14-Dec-09 12:12 
GeneralRe: Service does not start Pin
Migounette14-Dec-09 12:41
Migounette14-Dec-09 12:41 
GeneralRe: Service does not start Pin
Jimmanuel14-Dec-09 13:15
Jimmanuel14-Dec-09 13:15 
GeneralRe: Service does not start [modified] Pin
Jordanwb14-Dec-09 17:15
Jordanwb14-Dec-09 17:15 
GeneralRe: Service does not start Pin
Jimmanuel15-Dec-09 1:01
Jimmanuel15-Dec-09 1:01 
GeneralRe: Service does not start Pin
Jordanwb15-Dec-09 2:18
Jordanwb15-Dec-09 2:18 
GeneralRe: Service does not start Pin
Jimmanuel15-Dec-09 3:26
Jimmanuel15-Dec-09 3:26 
GeneralRe: Service does not start [modified] Pin
Jordanwb15-Dec-09 5:31
Jordanwb15-Dec-09 5:31 
GeneralRe: Service does not start Pin
Jimmanuel15-Dec-09 6:33
Jimmanuel15-Dec-09 6:33 
GeneralRe: Service does not start Pin
Jordanwb15-Dec-09 7:17
Jordanwb15-Dec-09 7:17 
QuestionPerhaps a threading problem? Pin
George Quarton14-Dec-09 10:12
George Quarton14-Dec-09 10:12 
AnswerRe: Perhaps a threading problem? Pin
Luc Pattyn14-Dec-09 11:56
sitebuilderLuc Pattyn14-Dec-09 11:56 
GeneralRe: Perhaps a threading problem? Pin
George Quarton14-Dec-09 12:17
George Quarton14-Dec-09 12:17 
GeneralRe: Perhaps a threading problem? Pin
Luc Pattyn14-Dec-09 12:41
sitebuilderLuc Pattyn14-Dec-09 12:41 
GeneralRe: Perhaps a threading problem? Pin
George Quarton14-Dec-09 12:45
George Quarton14-Dec-09 12:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.