crop_duster Posted March 17, 2019 Share Posted March 17, 2019 (edited) This is a function to insert A Number at A Position in a dynamic array ; 1/ I don't understand from the line "moveCount". What is moveCount for , and, Why move count = size - index; 2/ what in the function "memmove" in c++ 3/ could you please explain the codes from the line "ARROW" to the end ? Thank you so much for helping me ( I am just a stupid child trying to mess around with code ) Edited March 17, 2019 by crop_duster Link to comment https://www.neowin.net/forum/topic/1380848-dynamic-array-in-c-please-help-me-i-dont-understand-some-code-line-somebody-please-explain-them-for-me/ Share on other sites More sharing options...
0 Matthew S. Posted March 21, 2019 Share Posted March 21, 2019 The moveCount var is basically getting the size of the array minus the index of where you want to insert the new value within the array (the function name is DynamicArray::insertAt after all), the if statement makes sure it is an array and if, it's not using memmove to increase the size allocated. http://www.cplusplus.com/reference/cstring/memmove/ Quote memmove void * memmove ( void * destination, const void * source, size_t num ); Move block of memory Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap. The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data. The function does not check for any terminating null character in source - it always copies exactly num bytes. To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least numbytes. Parameters destination Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*. source Pointer to the source of data to be copied, type-casted to a pointer of type const void*. num Number of bytes to copy. size_t is an unsigned integral type. Expand Link to comment https://www.neowin.net/forum/topic/1380848-dynamic-array-in-c-please-help-me-i-dont-understand-some-code-line-somebody-please-explain-them-for-me/#findComment-598428952 Share on other sites More sharing options...
Question
crop_duster
This is a function to insert A Number at A Position in a dynamic array ;
1/ I don't understand from the line "moveCount". What is moveCount for , and, Why move count = size - index;
2/ what in the function "memmove" in c++
3/ could you please explain the codes from the line "ARROW" to the end ?
Thank you so much for helping me ( I am just a stupid child trying to mess around with code
)
Link to comment
https://www.neowin.net/forum/topic/1380848-dynamic-array-in-c-please-help-me-i-dont-understand-some-code-line-somebody-please-explain-them-for-me/Share on other sites
1 answer to this question
Recommended Posts