Bug 929

Summary: nms-p2p-nix.cc uses variable length array
Product: ns-3 Reporter: Quincy Tse <quincy.tse>
Component: examplesAssignee: Josh Pelkey <jpelkey>
Status: RESOLVED FIXED    
Severity: normal CC: mathieu.lacage, ns-bugs
Priority: P3    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: Proposed patch.
alternative patch using nested new[]

Description Quincy Tse 2010-05-30 22:52:46 UTC
nms-p2p-nix.cc uses variable length array, which cannot be compiled using some compilers (especially strict standards-compilent compilers like clang). Variable length array is part of C99 but does not comply with C++ standards (not in C++98, rejected for C++0x).
Comment 1 Quincy Tse 2010-05-30 22:53:32 UTC
Tried to cc the bug to original author, but the author is not registered on bugzilla.
Comment 2 Quincy Tse 2010-05-31 01:19:31 UTC
Created attachment 901 [details]
Proposed patch.

Proposed patch attached. Quite an ugly way to go about it (making 2D/3D array classes so that the main logic code doesn't have to change, but i can't see an easy way around it)

Haven't tested it yet because the test runs too long on my slow computer (even the original code take very long). I don't expect behaviours to have changed, but may have memory leaks due to the new[] operators.
Comment 3 Josh Pelkey 2010-08-10 22:48:33 UTC
(In reply to comment #2)
> Created an attachment (id=901) [details]
> Proposed patch.
> 
> Proposed patch attached. Quite an ugly way to go about it (making 2D/3D array
> classes so that the main logic code doesn't have to change, but i can't see an
> easy way around it)
> 
> Haven't tested it yet because the test runs too long on my slow computer (even
> the original code take very long). I don't expect behaviours to have changed,
> but may have memory leaks due to the new[] operators.

Do you think it would work if you used 2d and 3d std::vectors instead of creating these new classes and messing with dynamic arrays?

example: std::vector<std::vector<NodeContainer> > nodes_net0[nCN][3]
Comment 4 Quincy Tse 2010-08-11 01:28:34 UTC
(In reply to comment #3)
> Do you think it would work if you used 2d and 3d std::vectors instead of
> creating these new classes and messing with dynamic arrays?
> 
> example: std::vector<std::vector<NodeContainer> > nodes_net0[nCN][3]

Haven't worked with NS3 for a while now (I'm spending time analysing my data) - from memory, I chose not to use vector because the lengths are not fixed. There'll also need to be code to initialise the outside vectors. (I suppose we can use the constructor taking in default variable, but the code calling that constructor will look awful when we're looking at more than a couple of dimensions.)
Comment 5 Quincy Tse 2010-10-26 22:56:54 UTC
Created attachment 1006 [details]
alternative patch using nested new[]
Comment 6 Mathieu Lacage 2011-08-10 12:39:35 UTC
(In reply to comment #5)
> Created attachment 1006 [details]
> alternative patch using nested new[]

I read patch 2 and was about to suggest doing what you did in patch 1. applied patch 1 as obvious.

changeset: a26626a4f5bf