core dump stack indicates SIGSEGV due to vector<vector> usage












2














I have a code snippet that is behaving weirdly. The code is simply aiming to implement radix and bucket sort. When I comment in the main one of either sort and run it works perfectly. But when I enable both of them i am getting a core dump. And the weird part is core dump as indicated by the stack is crossing over into the stl_vector.h.



The code reference is here:- https://rextester.com/RUUDP10453



When i enable only one of the sorts like below in main it works fine.



  //doRadixSort(arr, size);
doBucketSort(arr, size);
or
doRadixSort(arr, size);
//doBucketSort(arr, size);


But when both are enabled there is segmentation fault after both sorts are completed as indicated by the



cout << "i am here at exit" << endl;


The core dump stack indicates some reference/hint at vector of vector buckets. But i have properly allocated and reserved it the required memory. so why this is happening i need some expertise to dig out. I have tried debugging this in eclipse CDT C++ for about 2 hrs with no lead.



Program terminated with signal SIGSEGV, Segmentation fault.
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
3976 >= ((char *) av->top + chunksize(av->top)), 0))
(gdb) where
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
#1 0x00007f66d6cf33dc in __GI___libc_free (mem=<optimized out>) at malloc.c:2966
#2 0x00000000004030fa in __gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::deallocate (this=0x7fffc6ffa060, __p=0xf98030) at /usr/include/c++/6.3.1/ext/new_allocator.h:110
#3 0x0000000000402d23 in std::allocator_traits<std::allocator<std::vector<int, std::allocator<int> > > >::deallocate (__a=..., __p=0xf98030, __n=10) at /usr/include/c++/6.3.1/bits/alloc_traits.h:442
#4 0x00000000004027ac in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_deallocate (this=0x7fffc6ffa060, __p=0xf98030, __n=10)
at /usr/include/c++/6.3.1/bits/stl_vector.h:178
#5 0x00000000004025e4 in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~_Vector_base (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:160
#6 0x000000000040211d in std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:427
#7 0x0000000000401d4b in doBucketSort (arr=0x7fffc6ffa100, size=@0x7fffc6ffa0f8: 12) at tako.cpp:97
#8 0x0000000000401e29 in main (argc=1, argv=0x7fffc6ffa218) at tako.cpp:141
(gdb)









share|improve this question


















  • 1




    In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
    – rafix07
    Nov 10 at 14:59












  • I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
    – Deepti Kulkarni
    Nov 11 at 0:17










  • can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
    – Deepti Kulkarni
    Nov 11 at 0:22










  • I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
    – Deepti Kulkarni
    Nov 11 at 9:22






  • 1




    Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
    – rafix07
    Nov 11 at 9:26


















2














I have a code snippet that is behaving weirdly. The code is simply aiming to implement radix and bucket sort. When I comment in the main one of either sort and run it works perfectly. But when I enable both of them i am getting a core dump. And the weird part is core dump as indicated by the stack is crossing over into the stl_vector.h.



The code reference is here:- https://rextester.com/RUUDP10453



When i enable only one of the sorts like below in main it works fine.



  //doRadixSort(arr, size);
doBucketSort(arr, size);
or
doRadixSort(arr, size);
//doBucketSort(arr, size);


But when both are enabled there is segmentation fault after both sorts are completed as indicated by the



cout << "i am here at exit" << endl;


The core dump stack indicates some reference/hint at vector of vector buckets. But i have properly allocated and reserved it the required memory. so why this is happening i need some expertise to dig out. I have tried debugging this in eclipse CDT C++ for about 2 hrs with no lead.



Program terminated with signal SIGSEGV, Segmentation fault.
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
3976 >= ((char *) av->top + chunksize(av->top)), 0))
(gdb) where
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
#1 0x00007f66d6cf33dc in __GI___libc_free (mem=<optimized out>) at malloc.c:2966
#2 0x00000000004030fa in __gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::deallocate (this=0x7fffc6ffa060, __p=0xf98030) at /usr/include/c++/6.3.1/ext/new_allocator.h:110
#3 0x0000000000402d23 in std::allocator_traits<std::allocator<std::vector<int, std::allocator<int> > > >::deallocate (__a=..., __p=0xf98030, __n=10) at /usr/include/c++/6.3.1/bits/alloc_traits.h:442
#4 0x00000000004027ac in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_deallocate (this=0x7fffc6ffa060, __p=0xf98030, __n=10)
at /usr/include/c++/6.3.1/bits/stl_vector.h:178
#5 0x00000000004025e4 in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~_Vector_base (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:160
#6 0x000000000040211d in std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:427
#7 0x0000000000401d4b in doBucketSort (arr=0x7fffc6ffa100, size=@0x7fffc6ffa0f8: 12) at tako.cpp:97
#8 0x0000000000401e29 in main (argc=1, argv=0x7fffc6ffa218) at tako.cpp:141
(gdb)









share|improve this question


















  • 1




    In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
    – rafix07
    Nov 10 at 14:59












  • I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
    – Deepti Kulkarni
    Nov 11 at 0:17










  • can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
    – Deepti Kulkarni
    Nov 11 at 0:22










  • I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
    – Deepti Kulkarni
    Nov 11 at 9:22






  • 1




    Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
    – rafix07
    Nov 11 at 9:26
















2












2








2







I have a code snippet that is behaving weirdly. The code is simply aiming to implement radix and bucket sort. When I comment in the main one of either sort and run it works perfectly. But when I enable both of them i am getting a core dump. And the weird part is core dump as indicated by the stack is crossing over into the stl_vector.h.



The code reference is here:- https://rextester.com/RUUDP10453



When i enable only one of the sorts like below in main it works fine.



  //doRadixSort(arr, size);
doBucketSort(arr, size);
or
doRadixSort(arr, size);
//doBucketSort(arr, size);


But when both are enabled there is segmentation fault after both sorts are completed as indicated by the



cout << "i am here at exit" << endl;


The core dump stack indicates some reference/hint at vector of vector buckets. But i have properly allocated and reserved it the required memory. so why this is happening i need some expertise to dig out. I have tried debugging this in eclipse CDT C++ for about 2 hrs with no lead.



Program terminated with signal SIGSEGV, Segmentation fault.
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
3976 >= ((char *) av->top + chunksize(av->top)), 0))
(gdb) where
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
#1 0x00007f66d6cf33dc in __GI___libc_free (mem=<optimized out>) at malloc.c:2966
#2 0x00000000004030fa in __gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::deallocate (this=0x7fffc6ffa060, __p=0xf98030) at /usr/include/c++/6.3.1/ext/new_allocator.h:110
#3 0x0000000000402d23 in std::allocator_traits<std::allocator<std::vector<int, std::allocator<int> > > >::deallocate (__a=..., __p=0xf98030, __n=10) at /usr/include/c++/6.3.1/bits/alloc_traits.h:442
#4 0x00000000004027ac in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_deallocate (this=0x7fffc6ffa060, __p=0xf98030, __n=10)
at /usr/include/c++/6.3.1/bits/stl_vector.h:178
#5 0x00000000004025e4 in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~_Vector_base (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:160
#6 0x000000000040211d in std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:427
#7 0x0000000000401d4b in doBucketSort (arr=0x7fffc6ffa100, size=@0x7fffc6ffa0f8: 12) at tako.cpp:97
#8 0x0000000000401e29 in main (argc=1, argv=0x7fffc6ffa218) at tako.cpp:141
(gdb)









share|improve this question













I have a code snippet that is behaving weirdly. The code is simply aiming to implement radix and bucket sort. When I comment in the main one of either sort and run it works perfectly. But when I enable both of them i am getting a core dump. And the weird part is core dump as indicated by the stack is crossing over into the stl_vector.h.



The code reference is here:- https://rextester.com/RUUDP10453



When i enable only one of the sorts like below in main it works fine.



  //doRadixSort(arr, size);
doBucketSort(arr, size);
or
doRadixSort(arr, size);
//doBucketSort(arr, size);


But when both are enabled there is segmentation fault after both sorts are completed as indicated by the



cout << "i am here at exit" << endl;


The core dump stack indicates some reference/hint at vector of vector buckets. But i have properly allocated and reserved it the required memory. so why this is happening i need some expertise to dig out. I have tried debugging this in eclipse CDT C++ for about 2 hrs with no lead.



Program terminated with signal SIGSEGV, Segmentation fault.
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
3976 >= ((char *) av->top + chunksize(av->top)), 0))
(gdb) where
#0 _int_free (av=0x7f66d702eb00 <main_arena>, p=0xf98020, have_lock=0) at malloc.c:3976
#1 0x00007f66d6cf33dc in __GI___libc_free (mem=<optimized out>) at malloc.c:2966
#2 0x00000000004030fa in __gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::deallocate (this=0x7fffc6ffa060, __p=0xf98030) at /usr/include/c++/6.3.1/ext/new_allocator.h:110
#3 0x0000000000402d23 in std::allocator_traits<std::allocator<std::vector<int, std::allocator<int> > > >::deallocate (__a=..., __p=0xf98030, __n=10) at /usr/include/c++/6.3.1/bits/alloc_traits.h:442
#4 0x00000000004027ac in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_deallocate (this=0x7fffc6ffa060, __p=0xf98030, __n=10)
at /usr/include/c++/6.3.1/bits/stl_vector.h:178
#5 0x00000000004025e4 in std::_Vector_base<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~_Vector_base (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:160
#6 0x000000000040211d in std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::~vector (this=0x7fffc6ffa060, __in_chrg=<optimized out>)
at /usr/include/c++/6.3.1/bits/stl_vector.h:427
#7 0x0000000000401d4b in doBucketSort (arr=0x7fffc6ffa100, size=@0x7fffc6ffa0f8: 12) at tako.cpp:97
#8 0x0000000000401e29 in main (argc=1, argv=0x7fffc6ffa218) at tako.cpp:141
(gdb)






c++11 coredump bucket-sort






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 13:16









Deepti Kulkarni

747




747








  • 1




    In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
    – rafix07
    Nov 10 at 14:59












  • I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
    – Deepti Kulkarni
    Nov 11 at 0:17










  • can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
    – Deepti Kulkarni
    Nov 11 at 0:22










  • I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
    – Deepti Kulkarni
    Nov 11 at 9:22






  • 1




    Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
    – rafix07
    Nov 11 at 9:26
















  • 1




    In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
    – rafix07
    Nov 10 at 14:59












  • I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
    – Deepti Kulkarni
    Nov 11 at 0:17










  • can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
    – Deepti Kulkarni
    Nov 11 at 0:22










  • I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
    – Deepti Kulkarni
    Nov 11 at 9:22






  • 1




    Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
    – rafix07
    Nov 11 at 9:26










1




1




In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
– rafix07
Nov 10 at 14:59






In both functions you did the same mistake - reserve was used instead of resize. reserve changes the capacity of vector, size is untouched. So before and after calling reserve size of buckets vector is 0, then you call operator for empty vector it leads to UB.
– rafix07
Nov 10 at 14:59














I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
– Deepti Kulkarni
Nov 11 at 0:17




I got your point , it works now!!! It was all due to only memory being reserved and actually proper vector interface not being used to initialize the vectors inside the vector. Now i have below code. // Create the 10 buckets as indicated below. vector<vector<int>> buckets; vector<int> emptyVec = { }; buckets.reserve(10); for(unsigned int i=0; i<=9; ++i) { buckets[i].reserve(size); buckets.push_back(emptyVec); }
– Deepti Kulkarni
Nov 11 at 0:17












can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
– Deepti Kulkarni
Nov 11 at 0:22




can you upvote the question so that it can help me build my StackOverflow points? I could not see this question hence asked.
– Deepti Kulkarni
Nov 11 at 0:22












I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
– Deepti Kulkarni
Nov 11 at 9:22




I am very sorry rafix07, I jumped in excitement bit too early. Could you please take a look at my code modifications at rextester.com/RUUDP10453 , After a few more runs its again back to dumping the core. I am still unclear on which piece i am missing in the cleanup. I do vector clear which removes all items and then shrink to fit which releases the memory. still it is dumping the core and failing to run. Your help is appreciated.
– Deepti Kulkarni
Nov 11 at 9:22




1




1




Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
– rafix07
Nov 11 at 9:26






Call buckets.resize(10); instead of buckets.reserve(10);. So should be vector<vector<int>> buckets;, buckets.resize(10);, for(unsigned int i=0; i<=9; ++i) buckets[i].reserve(size); in both functions.
– rafix07
Nov 11 at 9:26














1 Answer
1






active

oldest

votes


















1














Alternatively, I found the below also works which is equivalent to the resize function.



vector<vector<int>> buckets; 
constexpr size_t size=10, bucketSize=10;
buckets.reserve(bucketSize);
for(unsigned int i=0; i<=bucketSize; ++i)
buckets.push_back({ });
for(unsigned int i=0; i<=bucketSize; ++i)
buckets[i].reserve(size);





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239325%2fcore-dump-stack-indicates-sigsegv-due-to-vectorvectorint-usage%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Alternatively, I found the below also works which is equivalent to the resize function.



    vector<vector<int>> buckets; 
    constexpr size_t size=10, bucketSize=10;
    buckets.reserve(bucketSize);
    for(unsigned int i=0; i<=bucketSize; ++i)
    buckets.push_back({ });
    for(unsigned int i=0; i<=bucketSize; ++i)
    buckets[i].reserve(size);





    share|improve this answer


























      1














      Alternatively, I found the below also works which is equivalent to the resize function.



      vector<vector<int>> buckets; 
      constexpr size_t size=10, bucketSize=10;
      buckets.reserve(bucketSize);
      for(unsigned int i=0; i<=bucketSize; ++i)
      buckets.push_back({ });
      for(unsigned int i=0; i<=bucketSize; ++i)
      buckets[i].reserve(size);





      share|improve this answer
























        1












        1








        1






        Alternatively, I found the below also works which is equivalent to the resize function.



        vector<vector<int>> buckets; 
        constexpr size_t size=10, bucketSize=10;
        buckets.reserve(bucketSize);
        for(unsigned int i=0; i<=bucketSize; ++i)
        buckets.push_back({ });
        for(unsigned int i=0; i<=bucketSize; ++i)
        buckets[i].reserve(size);





        share|improve this answer












        Alternatively, I found the below also works which is equivalent to the resize function.



        vector<vector<int>> buckets; 
        constexpr size_t size=10, bucketSize=10;
        buckets.reserve(bucketSize);
        for(unsigned int i=0; i<=bucketSize; ++i)
        buckets.push_back({ });
        for(unsigned int i=0; i<=bucketSize; ++i)
        buckets[i].reserve(size);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 at 12:05









        Deepti Kulkarni

        747




        747






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239325%2fcore-dump-stack-indicates-sigsegv-due-to-vectorvectorint-usage%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff