Answered by:
Byte pointer buffer becomes a bad pointer after a certain buffer location - memory corruption

Question
-
I have a byte pointer variable, in which I am adding buffer location by adding a unsigned integer value.
For example:
for (int i=0; i<22, i++)
{
//currentOffset = 50000 or may vary every time when it enters the loop
obj->byteVar = initailByte + totalOffset + currentOffset
totalOffset += currentOffset;
}
This I am adding in a for loop to increase the buffer location. At a certain point the byte pointer obj->byteVar becomes a bad pointer. What I am doing wrong here and how to store as much as buffer.
Note: InitialByte - a byte variable (initiallised to zero always), totalOffset - an unsigned integer, currentOffset - an unsigned integer,
Your suggestions will be real helpful. Thanks in advance.
pramod kumar bugudai
Thursday, August 25, 2016 3:31 PM
Answers
-
Hi pram,
>>"At a certain point the byte pointer obj->byteVar becomes a bad pointer. "
Bad pointer means the pointer point to a unsigned space.
>>"how to store as much as buffer."
I suggest you use a array to store a list of buffer and use ++ or -- for a add or remove a offset of a point. Code below is for your reference.
uint myArray[5] = { 1000, 2, 3, 17, 50 }; obj->byteVar = myArray; for (int i = 0; i < myArray.Length - 1; i++) { obj->byteVar++; }
Best Regards,
Li WangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by DotNet Wang Saturday, September 3, 2016 3:13 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, September 7, 2016 4:09 AM
Sunday, August 28, 2016 9:16 AM -
Hello,
I want to know exactly the purpose of your project. I dont know about anyone else but this snippet
seems incorrect way to adjust memory allocation, escpecially in C++. Managed is more secure
when memory allocation/resize/de-allocations are required. I find the code snippet to be suspsect.
Please explain further with more details about your project and information about the versions of OS,
Visual Studio, 3rd Party libraries, etc.
Thanks :)
- Proposed as answer by DotNet Wang Saturday, September 3, 2016 3:13 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, September 7, 2016 4:09 AM
Monday, August 29, 2016 12:46 AM
All replies
-
Hi pram,
>>"At a certain point the byte pointer obj->byteVar becomes a bad pointer. "
Bad pointer means the pointer point to a unsigned space.
>>"how to store as much as buffer."
I suggest you use a array to store a list of buffer and use ++ or -- for a add or remove a offset of a point. Code below is for your reference.
uint myArray[5] = { 1000, 2, 3, 17, 50 }; obj->byteVar = myArray; for (int i = 0; i < myArray.Length - 1; i++) { obj->byteVar++; }
Best Regards,
Li WangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by DotNet Wang Saturday, September 3, 2016 3:13 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, September 7, 2016 4:09 AM
Sunday, August 28, 2016 9:16 AM -
Hello,
I want to know exactly the purpose of your project. I dont know about anyone else but this snippet
seems incorrect way to adjust memory allocation, escpecially in C++. Managed is more secure
when memory allocation/resize/de-allocations are required. I find the code snippet to be suspsect.
Please explain further with more details about your project and information about the versions of OS,
Visual Studio, 3rd Party libraries, etc.
Thanks :)
- Proposed as answer by DotNet Wang Saturday, September 3, 2016 3:13 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, September 7, 2016 4:09 AM
Monday, August 29, 2016 12:46 AM