Guest User

Untitled

a guest
Dec 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. \ Print function
  7. void PrintVector(vector<int> v)
  8. {
  9. for( int i = 0; i < v.size(); i++ )
  10. {
  11. cout << v[i] << ", ";
  12. }
  13. cout << endl;
  14. }
  15.  
  16. int main()
  17. {
  18.  
  19. vector<int> vector1;
  20. vector<int> vector2;
  21. vector<int> *ptrvector;
  22.  
  23. \Do some assignment so the vectors have values
  24. for( int i = 0; i<3; i++)
  25. {
  26. vector1.push_back(i);
  27. vector2.push_back(2*i);
  28. }
  29. \Assign the pointer to the address of vector1.
  30. ptrvector = &vector1;
  31.  
  32. \Print out:
  33. PrintVector(vector1); \ (1,2,3)
  34. PrintVector(vector2); \ (2,4,6)
  35. PrintVector(*ptrvector); \ (1,2,3)
  36. \ We should see that lines 1 and 3 are the same
  37.  
  38. \BROKEN BIT::
  39.  
  40. \Ideally want something like
  41. ptrvector[0] = &vector2[2];
  42. PrintVector(*ptrvector); \ (6,2,3);
  43.  
  44. \Such that if I were to do this:
  45. vector2[2] = 20;
  46. PrintVector(*ptrvector); \ It should change as a side effect: (20,2,3)
  47.  
  48.  
  49. }
  50.  
  51. TArray<FColor> ColorData;
  52. TArray<FColor> *ptrColorData
  53. //Where TArray is essentially a vector. FColor is a struct with members (R,G,B,A)
  54.  
  55. //ColorData is initialised somewhere and we set the ptrColorData to the address
  56. ptrColorData = &ColorData;
  57.  
  58. //Somewhere down the line we have a long loop whereby we do
  59. ColorData[i].B = somedata[i];
  60. ColorData[i].G = somedata[i+1];
  61. ColorData[i].R = somedata[i+3];
  62.  
  63. //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
  64.  
  65. ptrColorData[i].B = &somedata[i];
  66. ptrColorData[i].G = &somedata[i+1];
  67. ptrColorData[i].R = &somedata[i+3];
  68.  
  69. // this is only called once to initialize. Because the memory address
  70. //is unchanging and somedata changes by functions on its own it means when
  71. // I tell my unreal engine to update a texture by passing (*ptrColorData)
  72. // to a function it automatically has the new data when that function is
  73. // next called.
Add Comment
Please, Sign In to add comment