File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ const  std  =  @import ("std" );
2+ 
3+ fn  printMap (map : * const  [][]u8 ) void  {
4+     std .debug .print ("\n " , .{});
5+     for  (0.. map .len ) | x |  {
6+         const  row  =  map .* [x ];
7+         std .debug .print ("{d: >3}    " , .{x });
8+         for  (0.. row .len ) | y |  {
9+             std .debug .print ("{c}" , .{map .* [x ][y ]});
10+         }
11+         std .debug .print ("\n " , .{});
12+     }
13+ }
14+ 
15+ fn  fillMap (map : * const  [][]u8 ) void  {
16+     for  (0.. map .len ) | x |  {
17+         const  row  =  map .* [x ];
18+         for  (0.. row .len ) | y |  {
19+             map .* [x ][y ] =  '#' ;
20+         }
21+     }
22+ }
23+ 
24+ pub  fn  main () ! void  {
25+     var  arena  =  std .heap .ArenaAllocator .init (std .heap .page_allocator );
26+     defer  arena .deinit ();
27+     const  allocator  =  arena .allocator ();
28+ 
29+     var  map  =  try  allocator .alloc ([]u8 , 10 );
30+     for  (0.. map .len ) | x |  {
31+         map [x ] =  try  allocator .alloc (u8 , 12 );
32+         for  (0.. map [x ].len ) | y |  {
33+             map [x ][y ] =  '.' ;
34+         }
35+     }
36+     printMap (& map );
37+ 
38+     const  map_copy : [][]u8  =  try  allocator .alloc ([]u8 , map .len );
39+     for  (0.. map .len ) | x |  {
40+         map_copy [x ] =  try  allocator .alloc (u8 , map [x ].len );
41+         for  (0.. map [x ].len ) | y |  map_copy [x ][y ] =  map [x ][y ];
42+     }
43+ 
44+     std .debug .print ("\n Map:" , .{});
45+     printMap (& map );
46+     std .debug .print ("\n Copy:" , .{});
47+     printMap (& map_copy );
48+     std .debug .print ("\n After Fill:" , .{});
49+     fillMap (& map );
50+     printMap (& map );
51+     printMap (& map_copy );
52+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments