Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- \ Print function
- void PrintVector(vector<int> v)
- {
- for( int i = 0; i < v.size(); i++ )
- {
- cout << v[i] << ", ";
- }
- cout << endl;
- }
- int main()
- {
- vector<int> vector1;
- vector<int> vector2;
- vector<int> *ptrvector;
- \Do some assignment so the vectors have values
- for( int i = 0; i<3; i++)
- {
- vector1.push_back(i);
- vector2.push_back(2*i);
- }
- \Assign the pointer to the address of vector1.
- ptrvector = &vector1;
- \Print out:
- PrintVector(vector1); \ (1,2,3)
- PrintVector(vector2); \ (2,4,6)
- PrintVector(*ptrvector); \ (1,2,3)
- \ We should see that lines 1 and 3 are the same
- \BROKEN BIT::
- \Ideally want something like
- ptrvector[0] = &vector2[2];
- PrintVector(*ptrvector); \ (6,2,3);
- \Such that if I were to do this:
- vector2[2] = 20;
- PrintVector(*ptrvector); \ It should change as a side effect: (20,2,3)
- }
- TArray<FColor> ColorData;
- TArray<FColor> *ptrColorData
- //Where TArray is essentially a vector. FColor is a struct with members (R,G,B,A)
- //ColorData is initialised somewhere and we set the ptrColorData to the address
- ptrColorData = &ColorData;
- //Somewhere down the line we have a long loop whereby we do
- ColorData[i].B = somedata[i];
- ColorData[i].G = somedata[i+1];
- ColorData[i].R = somedata[i+3];
- //somedata is updated per tick, asigning ColorData per tick as well slows it down. I wish to be able to do something on the lines of this
- ptrColorData[i].B = &somedata[i];
- ptrColorData[i].G = &somedata[i+1];
- ptrColorData[i].R = &somedata[i+3];
- // this is only called once to initialize. Because the memory address
- //is unchanging and somedata changes by functions on its own it means when
- // I tell my unreal engine to update a texture by passing (*ptrColorData)
- // to a function it automatically has the new data when that function is
- // next called.
Add Comment
Please, Sign In to add comment