Question: I have the following pointer:

```
jfloat *verticesLocal;

```

And I want make a new copy to:

```
jfloat *vertices;

```

I want to copy the values from `verticesLocal` to `vertices`.

How can I do that? I've just tried the following command, but it doesn't work:

```
memcpy(vertices, verticesLocal, numVerticesLocal * sizeof(jfloat));

```

I can't see the error because I'm working with Android native code. Sorry.

Answer: 
The idea of "copying a pointer", when taken literally, is nothing more than a simple assignment.

```
int x = 5;
int* p1 = &x;
int* p2 = p1; // there, we copied the pointer.

```

In this case, both `p1` and `p2` point to the same data - the `int` variable `x`. However, because this is so trivial, I'm inclined to think that what you *really* are asking about is how to copy the *data* that the pointer points to.

In this case, it depends on the data type. If the pointer points to a simple buffer of [PODs](https://stackoverflow.com/questions/146452/what-are-pod-types-in-c), this involves allocating a separate buffer, and then using something like `memcpy` (or preferably `std::copy`) to copy the data. For example:

```
int* p1 = new int[100];
// ... fill p1 with values
int* p2 = new int[100]; // create a new buffer
std::copy(p1, p1 + 100, p2); // copy the data into p2

```

Or, you can use `memcpy` to copy the buffer byte-by-byte, since the buffer contains [PODs](https://stackoverflow.com/questions/146452/what-are-pod-types-in-c).

```
memcpy(p2, p1, 100 * sizeof(int));

```

However, if the pointed-to data is *not* a simple buffer, but rather a C++ object, you can't use `memcpy`. You need to perform a *deep copy* of the object, (usually using the object's copy constructor) to get a clone of the object. How this is done, or whether it's even possible, depends on the object. (Some objects are noncopyable.)

I have no clue what a `jfloat` is, but if the object is, for example, an `std::string`, you would just do something like:

```
std::string* s1; // assume this points to a valid string
std::string* s2 = new std::string();
*s2 = *s1; // copies s1 using s2's assignment operator

```

In this contrived example it would be preferable to avoid heap-allocation altogether, and just use stack variables. But it demonstrates the idea of copying a heap-allocated object.
this is how you copy an **array buffer** :

```
    unsigned char *pBufferSrc = new unsigned char[10];  
    unsigned char *pBufCpd = new unsigned char[10];

    for (int i = 0; i < 10; i++)
         pBufferSrc[i] = i;        // pBufferSrc = [0,1,2,3,4,5,6,7,8,9]

     memcpy(pBufCpd, pBufferSrc, 10);   // data from pBufferSrc is copied to pBufCpd (0,1,2,..9)

     delete []pBufferSrc;       // if even pBufferSrc buffer gets deleted, pBufCpd still has the data

```