Pointers Question

Ok, so I have an interesting situation that I would like some other peoples input on. Here is a brief explanation.

I am reading in a char array (all illegible data, dealing with it in the raw format). What I do with it is some multilayer demultiplexing. Basically, if I start with a string like this:

ABCDEABCDEABCDEABCDEABCDE

Then the first breakdown gets me one piece of data:

AAAAA

But then that piece can be further broken down to only take every 4th char, etc.

The code I am working with is someone elses code that I have to modify. And it does this demultiplexing properly. The problem is that I want to be able to take the information in the lowest layer, modify it, and then write it back to the file I got it from in place.

This may seem disgustingly confusing, but that is why I am here... it is driving me nuts. Any suggestions? Or just comments on how retarded I am because this is easier than I am making it out to be?

Thanks
This isn't hard at all.
So you have l layers and a stream of n characters. This means that the final length of each layer will be n/l (you'll have to compensate if n is not divisible by l).
What this means is you'll have l arrays of size n/l:
T arrays[l][n/l];
(I'm simplifying. In your code, you'll have to use dynamic allocation if you don't know at compile time the values of l and n.)
To fill the arrays, you just step through the message with i and fill an array according to the value of i:
arrays[i%l][i/l]=message[i];

Remultiplexing is merely the inverse process.

I hope my excessive use of variables wasn't confusing.
Last edited on
Oh, I didn't properly explain things...

The system I am working with is disgustingly complex. Not my doing, since I am working with legacy code. But it is massive.

Basically, the data I am working with can all be broken down into a bunch of different objects, but they all inherit from one base class. The easiest way to think of it is that all of the different classes are like russian stacking dolls. One big one contains X number of smaller ones, then the smaller ones can contain X number of even smaller ones, but they all have similar elements (hence inheriting from one base class).

So the information is being passed between classes (and thus between functions). So I guess what I am really having a problem with is passing the pointer between the methods and having it maintain the connection between the original data and the subclasses.

That make sense?
No, sorry. You seem to be contradicting yourself.
I am reading in a char array
the data I am working with can all be broken down into a bunch of different objects

Which is it?
Both.

So I have a file of data. A lot of data. The data itself (not the array, but the data IN the array) can be broken down into a bunch of smaller objects.

I read it in:

1
2
3
4
int fd = open(filename, blahblahblah);
while(bytesRead >0) {
  bytesRead = read(fd, buffer, blahblahblah);
}


So there I have my char array, buffer. Let's say it looks like this:

ABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFG

I then pass it into a container that we can call ContainerBig(), which is of type Container().

So what I do is call this:

1
2
ContainerBig bc;
bc->process(buffer);


ContainerBig then processes all of the data and starts to deinterleave it. It then puts all of the new stuff into a handful of smaller containers, called ContainerMedium() (also of type Container);

So ContainerBig() can have data enough for 4 ContainerMedium()s. In order to put the data into them, it would do something like this:

1
2
3
4
5
6
7
8
9
Container * medium[4];

for(int i = 0; i<4, i++) {	
  medium[i]->copy(placeInBuffer, bytesToRead);
}

for(int i = 0; i<4, i++) {
  medium[i]->checkContainer();	
}


What this does is use the Container() method called "copy()" to copy a certain number of bytes from the buffer, starting at "placeInBuffer" into medium[i]. It is far more complex than this, but just giving you the idea.

Then, checkContainer() will go into the ContainerMedium() object and begin processing the data in it. When it processes the data, it breaks it down further into ContainerSmall() objects (also of type Container). ContainerMedium() can have enough data for 4 ContainerSmalls().

ContainerSmall then does all of the processing it needs to find the bytes that I want to modify. It successfully does this, as I can get it to display exactly what I want it to. The problem is that I want to be able to modify this data and write it back into the correct place in the file that I got it from.

So...

ABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFG

Given this data, the first ContainerMedium object might contain:

ABCABCABCABCABCABC

And then the first ContainerSmall within the ContainerMedium might contain:

CCCCCC

So what I want to do is be able to take these CCCCCC bytes and change them to XXXXXX and write them back up into the file so that the original data that I pulled in would look like this:

ABXDEFGABXDEFGABXDEFGABXDEFGABXDEFGABXDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFGABCDEFG

(I bolded the content that got changed...)

I really think I am doing a terrible job of explaining what this is doing, but the code that they wrote is so ridiculous that I don't know how to explain it any better. Does this clear anything up at all about what I am trying to do and how I am currently doing it?
Topic archived. No new replies allowed.