source: tests/collections/string-ctx-manage.cfa @ 804bf677

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 804bf677 was 804bf677, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

String hybrid: Basic cases of solo alloc now working

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <string.hfa>
2#include <string_sharectx.hfa>
3#include <string_res.hfa>
4
5void baseline() {
6    string x = "hi";
7
8    string y = x; // construct y in same context, no write yet => no copy yet
9    assert( y.inner->Handle.s == x.inner->Handle.s);
10    sout | y; // hi
11
12    x = "bye";
13    y = x; // y in same context, no write yet => no copy yet
14    assert( y.inner->Handle.s == x.inner->Handle.s);
15    sout | y; // bye
16}
17
18void eagerCopy() {
19    string x = "hi";
20    string_sharectx c = { NEW_SHARING };
21
22    string y = x; // construct y in different context => eager copy
23    assert( y.inner->Handle.s != x.inner->Handle.s);
24    sout | y; // hi
25
26    x = "bye";
27    y = x; // y was already in different context => eager copy
28    assert( y.inner->Handle.s != x.inner->Handle.s);
29    sout | y; // bye
30}
31
32void soloAlloc() {
33    string x = "hi";
34    string_sharectx c = { NO_SHARING };
35   
36    string y = x; // y allocates into private pad, implying eager copy
37    assert( y.inner->Handle.s != x.inner->Handle.s);
38    sout | y; // hi
39
40    // -- following hits "need to implement actual growth"
41    //    and it passes if I modify string_res.cfa to oversize the owned heaps
42
43    // x = "bye";
44    // y = x; // into private y => eager copy
45    // assert( y.inner->Handle.s != x.inner->Handle.s);
46    // sout | y; // bye
47}
48
49
50int main() {
51    baseline();
52    eagerCopy();
53    soloAlloc();
54    printf("done\n");
55}
Note: See TracBrowser for help on using the repository browser.